Pregunta

I have 2 tables.

  1. tb_Employees
  2. tb_Orders

tb_Employees has the following fields

  1. empID
  2. name

tb_Orders has the following fields

  1. orderID
  2. clientName
  3. empAccepted (reference tb_Employees)
  4. empApproved (reference tb_Employees)

When I pull the data;

  • "empAccepted" works fine.
  • "empApproved" shows data from empAccepted

empApproved is not showing its own data.

Does anyone know how to properly map this in CF ORM?

<---------------- Added ---------------->

I have many fails.

I can post all of them - but, I think it's a waist of time.

NONE OF THEM WORKED

I want to learn how to properly map this scenario out. THE RIGHT WAY.

I thought I gave enough, basic info for mapping.

However, due to popular demand : )))))

Which 'FAIL' should I post?

I'm posting 1 of my fails. (I have over 12 fails).

12 different files on ways NOT to do it. : )))

I have changed this so many times. Took things out. Added things.

I just want to know how to map this scenario correctly.

tb_Orders.empApproved ... keeps showing data from ... tb_Orders.empAccepted

tb_Employees

<!---- properties ---->
<cfproperty     name="empID"                    
        fieldtype="id" 
        setter="false" 
        column="empID_pk" 
        generator="native"  />

<cfproperty     name="name" 
        type="string"  />



<cfproperty     name="approved" 
        fieldtype="one-to-many" 
        cfc="tb_Orders" 
        fkcolumn="empApproved"  />

<cfproperty     name="accepted" 
        fieldtype="one-to-many" 
        cfc="tb_Orders" 
        fkColumn="empAccepted"  />

tb_Orders

<!---- properties ---->
<cfproperty     name="orderID"                      
        fieldtype="id" 
        setter="false" 
        column="orderID_pk" 
        generator="native"  />

<cfproperty     name="clientName" 
        type="string"  />


<cfproperty     name="empAccepted"  
        insert="false" 
        update="false" 
        fieldtype="many-to-one" 
        cfc="tb_Employees" 
        inverse="true"  />


<cfproperty     name="empApproved"  
        insert="false" 
        update="false" 
        fieldtype="many-to-one" 
        cfc="tb_Employees" 
        inverse="true"  />
¿Fue útil?

Solución

give this a go.

<cfproperty name="empAccepted" type="tb_Employee"
        fieldtype="many-to-one"
        cfc="tb_Employee"
        fkcolumn="empAccepted"/>

<cfproperty name="empApproved" type="tb_Employee"
        fieldtype="many-to-one"
        cfc="tb_Employee"
        fkcolumn="empApproved"/>

Also, on tb_Employees, if you want that to control the relationship you'll probably want cascade and inverse there... like this

<cfproperty name="approved" type="Array"
    fieldtype="one-to-many"
    inverse="true"
    cfc="tb_Orders"
    fkcolumn="empApproved"
    singularname="tb_Order"
    cascade="all-delete-orphan"/>

Keep in mind, this is "Object" relational mapping, not "Relational Table" mapping. Its a good idea to get in the habit of thinking in "objects" and how they relate rather than your database.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top