Order EntityLoad() by field in linked table?

21 views
Skip to first unread message

Ivan McAvinchey

unread,
Nov 15, 2016, 1:39:34 PM11/15/16
to cf-orm-dev
I have two entities in a one-to-many relationship, Staff and StaffDepartment.

In Staff.cfc:

property name="department" fieldtype="many-to-one"
cfc="StaffDepartment" fkcolumn="departmentid"
insert="false" update="false" orderby="position asc";

In StaffDepartment.cfc:

property name="position" ormtype="int";

What I want is to return staff, ordered by department position. So I try:

rc.staff = entityLoad("Staff", {isactive = 1}, "department asc");

However this gives me the staff sorted by the primary key of StaffDepartment.

My question is whether this is possible using just EntityLoad()? I was hopeful that specifying orderby on department would do it but that only seems to apply if I was running getDepartment() on Staff (which would only in this case return one record anyway, so not applicable, would be the other way around).

Note I can do this fine using ORMExecuteQuery and HQL, my question is just is there a way to do this using EntityLoad() specifically!

rc.staff = ORMExecuteQuery("from Staff s
join fetch s.department d
where s.isactive = 1
order by d.position asc, s.position asc");

Nathan Strutz

unread,
Nov 16, 2016, 12:03:46 PM11/16/16
to cf-orm-dev
Ivan,
Your orderby attribute on the department property only applies when you use that link, so, Staff.getDepartment() will apply that orderby, but no other queries will.
Because you are trying to order one table by another, I think you are best off using the HQL.

-nathan strutz


--
You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cf-orm-dev+...@googlegroups.com.
To post to this group, send email to cf-or...@googlegroups.com.
Visit this group at https://groups.google.com/group/cf-orm-dev.
For more options, visit https://groups.google.com/d/optout.
--

-Nathan Strutz

Reply all
Reply to author
Forward
0 new messages