0
votes

Repeated column in mapping for entity: user column: userid (should be mapped with insert="false" update="false")

That is the error message I'm getting. I've got a user table (customer) that is self-referential. That way I can tell which user created which and when.

Here is my entity.

component  table="customer" output="false" accessors="true" persistent="true" {
  property name="userid"      column="userid"       ormtype="int"   fieldtype="id"    generator="identity";
  property name="firstname"   column="firstname"    ormtype="string";
  property name="lastname"    column="lastname"     ormtype="string";
  property name="email"       column="email"        ormtype="string";
  property name="active"      column="active"       type="boolean"  ormtype="boolean";
  property name="createdOn"   column="createdOn"    ormtype="date";
  property name="modifiedOn"  column="modifiedOn"   ormtype="date";
  property name="createdBy"   fieldtype="one-to-one"  cfc="user"    fkcolumn="userid" inverse="true";
  property name="modifiedBy"  fieldtype="one-to-one"  cfc="user"    fkcolumn="userid" inverse="true";
}

I've added what the error message tells me to add to each property so they now look like:

property name="createdBy"   fieldtype="one-to-one"  cfc="user"    fkcolumn="userid" inverse="true" insert="false" update="false";
property name="modifiedBy"  fieldtype="one-to-one"  cfc="user"    fkcolumn="userid" inverse="true" insert="false" update="false";

SOLUTION: I added inversejoincolumn="userid" and it worked. See below

property name="createdBy"     column="createdBy"      fieldtype="one-to-one"  cfc="user"    inversejoincolumn="userid";
property name="modifiedBy"    column="modifiedBy"     fieldtype="one-to-one"  cfc="user"    inversejoincolumn="userid";
1
So is the error still there after making your changes and calling OrmReload()? - CfSimplicity
I need to be able to save/update those columns (createdBy and modifiedBy), but yes, if I add that code to ALL of the userid columns, including the primary key, it works, but since I need to save the data, it doesn't technically 'work'. - pendo
You shouldn't need to add it to the identiy userid property. But anyway it seems you need to create specific keys for your 2 self-referential relationships. - CfSimplicity
This is what fixed it property name="modifiedBy" column="modifiedBy" fieldtype="one-to-one" cfc="user" inversejoincolumn="userid"; I added inversejoinclumn to both modifiedBy and createdBy. thank you to everyone for there suggestions. - pendo

1 Answers

0
votes

In your customers table create separate columns to record the IDs of the users who do the creating and modifying. You could call them creatorid and modifierid.

Then change the fkcolumn in your createdBy and modifiedBy relationships from userid to creatorid and modifierid respectively.