我有一个应用程序,其中包含许多体育俱乐部,每个俱乐部都有许多联系人。
每个联系人可以是多种类型中的一种,并且这些联系人有指定的显示顺序。
我想为实体关系中的联系人指定此排序顺序,但无法完全了解如何执行此操作。
为了澄清一点,这里是我的三个(简化的)实体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 :(得分:3)
听起来我需要覆盖club.cfc中的getContacts
来使用HQL进行自定义查找。不幸的是我不是HQL向导,我没有你的数据库来测试它。但这是我对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 }
);
}
我确信这不对,但希望它会让你开始。