1
votes

I am just starting out using ORM and I'm running into confusion.

Here is my error:

Error Occurred While Processing Request
Repeated column in mapping for entity: skill column: programTypeID (should be mapped with insert="false" update="false")

Here is a basic scenario I am using:

TABLES:

**ProgramType**
programTypeID (PK)
programType varchar(50)

**Skill**
skillID (PK)
Skill varchar(50)
programTypeID(int) (FK)

From my understanding my skill - programtype relationship is a many-to-one... Meaning Many Skills can only have 1 program Type... or 1 program type can be mapped to many skills.

Skill.cfc:

<cfcomponent persistent="true">

<cfproperty name="skillid" fieldType="id" generator="identity">
    <cfproperty name="skill" ormType="string">    
    <cfproperty name="programTypeID" ormType="integer">    
    <cfproperty name="programType" fieldtype="many-to-one" fkcolumn="programTypeID" cfc="programType">    
</cfcomponent>

ProgramType.cfc

<cfcomponent persistent="true" table="programtype">

    <cfproperty name="programtypeid" fieldType="id" generator="identity">
    <cfproperty name="programtype" ormType="string">

   <cfproperty name="skill" fieldType="one-to-many" type="array" cfc="skill" fkcolumn="programTypeID" inverse="true">

</cfcomponent>

SkillEditForm.cfm

<cfoutput>
<form class="form-horizontal" action="submit.cfm" method="post">
<input name="skillid" type="hidden" value="#skill.getSkillid()#">

  <div class="control-group">
    <label class="control-label" for="programTypeID">Skill</label>
    :
    <div class="controls">
        <select name="programTypeID">
        <cfloop index="programType" array="#programTypes#">
            <option value="#programType.getProgramTypeID()#"

            <cfif programType.getProgramtypeid() eq skillProgramType.getProgramTypeid()>selected</cfif>

            >#programType.getProgramType()#</option>
        </cfloop>
        </select>
    </div>
  </div>


  <div class="control-group">
    <label class="control-label" for="skill">Skill</label>
    :
    <div class="controls">
      <input type="text" id="skill" placeholder="" name="skill" value="#skill.getSkill()#">
    </div>
  </div>

  <div class="control-group">
    <div class="controls">
      <button type="submit" class="btn">Submit</button>
    </div>
  </div>                  

</form>
</cfoutput>

I find that if I remove programTypeID from the skill.cfc my error goes away. But, my confusion runs in, if programTYpeID is not defined in my CFC, when I go to add or update my entity on the submit.cfc page... how will I set the programTypeID from my select box on the form?

1

1 Answers

2
votes

You need to remove the programTypeId property, otherwise you will have 2 columns with that name as the relationship you define will create one.

You would first need to grab the program type that matches the ID passed in and then set that value in the Skill object such as (this assumes you have already created a Skill object)

var programType = entityLoadByPK( 'programType', form.programTypeId)
skill.setProgramType( programType )

As part of validation, you would also want to make sure that the programType is not null before trying to save.