Jason
Jason

Reputation: 1977

CF ORM - Cannot load the target CFC

This one is driving me batty.

I have setup ORM. When I run ORMReload(), I get the following error.

Cannot load the target CFC productCategories for the relation property category in CFC products.

Application.cfc ORM Config

this.ormEnabled = true;
this.ormsettings = {
      cfclocation = "_model"
};

products.cfc

component persistent="true" table="products" {
property name="id" fieldtype="id";
property name="productcode" ormtype="string";
property name="title" ormtype="string";
property name="introduction" ormtype="text";
property name="description" ormtype="text";
property name="image1" ormtype="string";
property name="image2" ormtype="string";
property name="image3" ormtype="string";
property name="deletedAt" ormtype="date";

property name="category" fieldtype="many-to-one" cfc="productCategories" fkcolumn="categoryid";

//init()
public function init(){
    return this;
}

//getByID()
public function getByID(required id=""){
    return entityLoadByPK("products",'18');
}

}

productCategories.cfc

component persistent="true" table="productCategories" {
property name="id" fieldtype="id";
property name="description" ormtype="string";

property name="products" fieldtype="one-to-many" cfc="products" fkcolumn="categoryid";

//init()
public function init(){
    return this;
}

public function get(){
    return entityload("productCategories");
}

}

I can get past this error by setting the full path in the cfc parameters, for example cfc="_model.products", but then I get the following error.

An association from the table products refers to an unmapped class:

Both CFCs are in the same folder. I have tried restarting CF Server. Pulling my hair out. Any suggestions hugely appreciated.

Upvotes: 1

Views: 652

Answers (3)

Jason
Jason

Reputation: 1977

Thanks FLepage and CfSimplicity for your suggestions.

I eventually worked it out to be a permissions issue on the folders. I moved the whole app to another dev server and it worked fine (more hair pulling).. eventually checked the permissions on the folders of the problematic version and once I reset permissions to give all necassary access it worked fine..

I had copied the files in from a PC to Mac, so OSX must have done something to the folder permissions when I copied the files/folders in. Not fun.

Thanks Again!

Upvotes: 0

CfSimplicity
CfSimplicity

Reputation: 2363

Try changing your cfclocation setting in Application.cfc to an absolute rather than relative path:

this.ormEnabled = true;
this.ormsettings = {
      cfclocation = ExpandPath( "_model" )
};

Upvotes: 1

JLepage.info
JLepage.info

Reputation: 11

Reload ORM every time you change your model. Check all names of object and relation name (case sensitively).

Check with "_model" and without on CFC names.

The error message indicates an unmapped class, so one or more names are wrong. Or doesn't exist for hibernate (reload would be necessary).

Upvotes: 1

Related Questions