Before ORM, if I wanted to display the combined output of a normalized table, I’d just do a quick CFQUERY, join the tables on the fields I want and display the output. I just can’t get my head wrapped around it using ORM.
For example with these two tables:
customers
(id,
name,
customerType)
customerTypes
(id,
Name)
How would you create a single entity you can load to display the following when the customerType field in customers links to an id in customerTypes?
customers.id, customers.name, customerTypes.name
All of the ORM relationship examples I’ve walked through for some reason can’t make me understand how to do it. It seems so simple it’s killing me. Any help shedding some light on this would be appreciated!
Or alternatively
<cfproperty name="type" type="string" column="Name" table="customerTypes" joincolumn="id">
see Join mapping in a CFC
So in your Customers
CFC you will need something like this:
<cfproperty name="customerType" type="CustomerTypes" fieldtype="many-to-one" cfc="CustomerTypes" fkcolumn="id" lazy="true" />
Then you should be able to dump an instance of a Customers
object and see that it has a customerType
property and hence you can write something like this:
<cfset cust = entityLoad("Customers", 1) />
<cfset type = cust.getCustomerType().getName() />
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With