I have posted about this on my blog, but if anyone here could give their 
opinion I would very much like to hear it.

I am trying to understand if I am looking at ORM correctly in terms of a 
many-to-many relationship.

blog post is here 
http://www.cfcoffee.co.uk/index.cfm/2010/9/20/Head-Spin-Moment-ORM-manytomany-Help

for the sake of cftalk I have posted again below. thanks :)


------------------------

Below I have two tables. Users and Monsters. A user can have many monsters, and 
a monster can have many users. Therefore I have a many-to-many relationship. 
Now I decide to include a join table called mostercollected to normalise the 
table somewhat. So below is what I come up with.

/**
* user
*/
component output="false" persistent="true" {

property name="user_id" column="user_id" type="numeric"
ormtype="int" fieldtype="id" generator="increment";

property name="user_name" column="user_name"
type="string" ormtype="string";
    
     /* link tables */    
property name="monsters" fieldtype="many-to-many"
CFC="monsters" FKColumn="user_id" singularname="monsters"
inversejoincolumn="monster_id" linktable="monstersCollected";

users function init() output=false{
return this;
}

}




/**
* monsters
*/
component output="false" persistent="true" {

property name="monster_id" column="monster_id" type="numeric"
ormtype="int" fieldtype="id" generator="increment";

property name="monster_name" column="monster_name" type="string"
ormtype="string" ;

/* link tables */
property name="users" fieldtype="many-to-many" CFC="users"
FKColumn="monster_id" singularname="monsters"
     inversejoincolumn="user_id" linktable="monstersCollected";

monsters function init() output=false{
return this;
}

}


/* Join table */    



component entityname="UserMonster" persistent="true" accessors="true"
table="monstersCollected"
{
property name="user_id"
fieldtype="id,many-to-one"
cfc="users"
cascade="all"
fkcolumn="user_id";

property name="monster_id"
fieldtype="id,many-to-one"
cfc="monsters"
cascade="all"
fkcolumn="monster_id";

}


Now if I dump a user to screen, yes I can see all the monsters that each user 
has (cool), but the array continues down more, showing all monsters and all 
users that belong to that monster, effectively repeating data (bad, right?).


My concern is that of performance. If every time I want to get a user and I 
then get monsters + monster again and users that belong to that monster (head 
spin, moment), this seems like a lot of overhead (or is it?).

Is this the issue I am making it out to be? 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:337253
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to