I have an entity called ForumTopic
This has a one to many relationship with ForumReplies.
I want to get all Replies from the topic that have a property ‘enabled’ set to true, but I can’t quite work out the best way to do this.
I thought the best way was to put a method in my ForumReplies entity and use the Coldbox ORM findAllWhere method, but then I can’t filter on the topic, because topicid is not a field, topic is an association. Here is my entity with the getPublishedReplies() method.
`
component persistent=“true” table=“forumtopics” hint=“Forum Topics” extends=“coldbox.system.orm.hibernate.ActiveEntity”{
property name=“id” fieldtype=“id” generator=“native”;
property name=“orgID” ormtype=“integer”;
property name=“groupID” ormtype=“ineger” dbdefault=“0” default=“0”;
property name=“title” ormtype=“string” length=“250”;
property name=“body” ormtype=“text”;
property name=“attachment” ormtype=“string” length=“250”;
property name=“enabled” ormtype=“boolean” default=“true”;
property name=“tstamp” ormtype=“timestamp” ;
//associations
property name=“profile” fieldtype=“many-to-one” cfc=“Profile” fkcolumn=“profileid” inverse=“true” lazy=“true”;
property name=“category” fieldtype=“many-to-one” cfc=“ForumCategory” fkcolumn=“categoryid” inverse=“true” lazy=“true”;
property name=“replies” fieldtype=“one-to-many” type=“array” singularName=“reply” cascade=“delete-orphan” cfc=“ForumReply” fkcolumn=“topicid”;
//getPublishedReplies
public function getPublishedReplies(){
var replies = findAllWhere(entityName=“ForumReplies”,criteria={ topicid = this.getID(), enabled = true });
return replies;
}
}
`
Can anyone suggest how best I would go about getting the associated replies for a topic, while being able to filter on on fields in the associated entity? All I can think is that I may need to resort to Raw SQL, but surely there is a better way than that?
Many thanks for any pointers.
Jason