2011-07-27 3 views
2

각기 많은 연락처가있는 다수의 스포츠 클럽이 포함 된 앱이 있습니다.ColdFusion ORM : 엔티티 관계의 정렬 순서

각 연락처는 여러 유형 중 하나 일 수 있으며 지정된 연락처 순서가 있습니다.

내 엔티티 관계에있는 연락처에 대해이 정렬 순서를 지정하려고하지만이를 수행하는 방법을 알 수 없습니다.

여기, 것들을 조금 명확히 내 세 (간체) 엔티티 CFC가 있습니다하려면 :

club.cfc

component persistent="true" table="clubs" 
{ 
    // identifier 
    property name="clubid" fieldtype="id" setter="false" generator="identity"; 

    // properties 
    property name="clubname"; 

    // relationships 
    property name="contacts" cfc="contact" singularname="contact" fieldtype="one-to-many" fkcolumn="clubid"; 
} 

contact.cfc

component persistent="true" table="contacts" 
{ 
    // identifier 
    property name="contactid" fieldtype="id" setter="false" generator="identity"; 

    // properties 
    property name="clubid"; 
    property name="name"; 

    //relationships 
    property name="contacttype" cfc="contacttype" fieldtype="many-to-one" fkcolumn="type"; 
} 

contacttype .cfc

component persistent="true" table="contacttypes" 
{ 
    // identifier 
    property name="type" fieldtype="id" insert="false" update="false"; 

    // properties 
    property name="typename"; 
    property name="displayorder";  
} 

요약하면, 내가 원하는 것은 contacttype의 displayorder 값에 따라 연락처를 정렬하여 클럽을 얻는 것입니다.

제안 사항?

+0

[이 질문에 대한 Sam Farmer의 제안 (http://stackoverflow.com/q/3945734/8174)을 사용할 수 있는지 궁금합니다. 그 질문은 귀하와 유사한 상황 인 것 같습니다. –

답변

3

HQL을 사용하여 사용자 정의 조회를 수행하려면 club.cfc에서 getContacts을 대체해야하는 것처럼 들립니다. 불행히도 나는 HQL 마법사가 아니며 이것을 테스트 할 데이터베이스가 없다.

public array getContacts() 
{ 
    return ormExecuteQuery(
     "from club cl, contact co, contacttype ct 
     where co.clubid = cl.clubid and cl = :thisClub 
     order by ct.displayorder" 
     , { thisClub = this } 
    ); 
} 

나는 그것이 옳지 않아 확신 해요, 그러나 희망은 당신이 시작하는 것이다 : 그러나 여기 HQL에서 내 다소 추측이다.

+0

방금 ​​시도해 보았지만 약간의 수정만으로 작동했지만 문제는 getContacts()를 실행할 때마다 (즉, 모든 연락처마다 한 번씩) 쿼리가 실행된다는 것입니다. 속성 관계를 통해이를 수행 할 수 있고 "조인"을 가져 오면 훨씬 더 효율적입니다 ... – sebduggan

+0

클럽 당 한 번 의미합니까? –