Associations question

14 views
Skip to first unread message

kwbarrett

unread,
May 23, 2013, 4:33:42 PM5/23/13
to cfwh...@googlegroups.com
Been away from CFWheels for a bit so pardon me if this question has an obvious answer.  I am having issues with associations. Basically, I have several one-to-many relationships.  I had no problem making those associations.  I set my call to returnas="Objects", so I get an array of objects back for my associations.  I have a Collection table with a creatorPerson object, CoCreatorPerson object, etc.  The issue comes in the other associations on those tables.  Person has a many-to-many relationship to Occupations via the PersonOccupations table.

Collection.cfc

<cfset belongsTo(name="creatorPerson", modelName="Person", foreignKey="creatorPersonID", joinType="outer")/>

Person.cfc
 <cfset hasMany("PersonOccupations")/>
 
PersonOccupation.cfc 
 <cfset belongsTo("Person")/> 
<cfset belongsTo("Occupation")/>

Occupation
<cfset hasMany("PersonOccupations")/>

 I make my call to the Collection model:

<cfset collection2 = model("Collection").findOne(where="id=#id#", returnAs="objects", include="creatorPerson")/>


What I want is all the Occupation objects for each creatorPerson object returned. But if I try: include="creatorPerson(PersonOccupations)" I get an error telling my I can't do this when returning objects.  The shortcuts don't seem to work either.  I know how to do this in conventional OO programming.  I have to be missing something here. Or is this something that is not allowed in CFWheels?  Additionally, I'm trying to figure out why I am getting an object back at all for creatorPerson if creatorPersonID IS NULL? I ask because after I get back the results I need to run some checks to go to the next step.  I would normally use IsObject() to determine if there is in fact a creatorPerson object for this collection and move on.  But since I am getting back an object full of null values I think isObject() would still return true.  Any help would be greatly appreciated.  Thanks.
CollectionResult.png
Reply all
Reply to author
Forward
0 new messages