ORM and relationships

Never done much with ORM before, so I thought I'd give it a test, and
getting stuck quite early on!

I have two objects, a User Object and a Company Object.

They're both in the model folder of my coldbox app.

However, I can't get relationships to work at all.

Here's my User Object:

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

  property name="userID" fieldType="id" type="numeric"

  property name="first_name" type="string" length="50";
  property name="surname" type="string" length="50";
  property name="email" type="string" length="50";
        property name="company" cfc="Company" fieldType="many-to-one"
  property name="password" type="string" length="50";
  property name="mobilePhone" type="string" length="15";
  property name="userType" type="string" default="customer"
  property name="isRegistered" type="boolean" default="false"
  User function init() output=false{
    return this;

And here's my Company Object:

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

  property name="companyID" fieldType="id" type="numeric"
        property name="name" type="string" length="50";
  property name="known_as" type="string" length="50";
  property name="email" type="string" length="50";
  property name="telephone" type="string" length="50";

  Company function init() output=false{
    return this;

Basically, when I start up my app, I get "Cannot find the component

If I switch the relationships around (and add User into company as
"one-to-many" I get: "Target component User defined for relation user
in cfc Company is not persistent."

Really stuck - anyone got any idea?

Just to update, if I move all my components out of model and put them
in the root - and then remove cfclocation="model" from
Application.cfc, then everything works.


Yea, I have found weird things with component discovery and ORM especially in MAC
Luis F. Majano
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Why do you have a function init() in your persistent object?

In ColdFusion 9 this is not needed, and specifically not needed for
persistent objects either.

Andrew Scott

I Just copied Luis' Task object from his TaskManager demo - it was
just to get something working that's all.

Did it work?

Yes it worked fine.

Although I have to keep the CFCs in the root and remove the
cfclocation attribute as I mentioned previously. So it's not ideal.

I'm not sure why - I'm running cf9 on CentOS. I have coldbox as a
mapping, maybe that has something to do with it....


I've seemed to fix it. I was using Application with Inheritance - and
that seemed to be the problem. I also had a problem where my database
fields weren't getting updated, even when I did drop-create.

When I switched to Application without inheritance, the drop-create
issue went away, as did the cfclocation issue - I now have my CFCs in
an orm folder.