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 值对俱乐部及其联系人进行排序。
建议?
I've got an app which contains a number of sports clubs, each having a number of contacts.
Each contact can be one of a number of types, and there's a specified display order for these.
I want to specify this sort order for the contacts in my entity relationship, but can't quite see how to do it.
To clarify things a little, here are my three (simplified) entity CFCs:
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";
}
So, in summary, what I want to do is get the club with its contacts sorted according to the displayorder value in contacttype.
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您需要重写club.cfc 中的
getContacts
才能使用HQL 进行自定义查找。不幸的是,我不是 HQL 向导,并且我没有您的数据库来对此进行测试。但这是我对 HQL 的一些疯狂猜测:我确信这是不对的,但希望它能帮助您入门。
Sounds to me like you need to override
getContacts
in club.cfc to do a custom lookup using HQL. Unfortunately I'm no HQL wizard, and I don't have your db to test this against. But here's my somewhat wild guess at the HQL:I'm sure that's not right, but hopefully it'll get you started.