1
votes

I have the following tables: users: userID primaryKey usersDependencies: userID, dependentUserID

Ex: users: 1, 2, 3, 4, 5 usersDependencies: 1, 2 1, 3 1, 4 2, 3

and the following components:

User.cfc

component  persistent="true" output="false" table="users"
{

property name="userID" type="int" unSavedValue="0" fieldtype="id" unique="true" notnull="true" generator="native" default="0" setter="false";

property name="dependencies" fieldtype="many-to-many" cfc="UserDependency" fkColumn="userID" inverseJoinColumn="dependentUserID" 
         singularname="dependency" type="array" cascade="all" linktable="usersDependencies" ;

}

UserDependency.cfc 

component  persistent="true" output="false" table="usersDependencies"
{

property name="userID" fieldtype="id,many-to-one" fkcolumn="userID" cfc="User" insert="false" update="false";


property name="dependentUserID" fieldtype="id,many-to-one" fkcolumn="userID" insert="false" update="false";

}

But the above mapping generates the following error: Repeated column in mapping for entity: UserDependency column: userID (should be mapped with insert="false" update="false")

Any idea how to set them?

Thanks

1

1 Answers

0
votes

many-to-many is usually something one should avoid in ORM. Try introducing a new entity and restructure the many-to-many into 2 many-to-one relationships. This generally works better and more flexible to extend later.

Having said that, if usersDependencies is just a link table, it should not be an entity. The cfc attribute should set to User instead because you want an array of users. Please follow the cf orm doc closely to make sure you have the concept nailed down.

However, I'm not even sure if ORM would work for this. I have a feeling cfdump may crash even with TOP 1 since it doesn't play well with lazy loading for your same type referencing many-to-many relationship.