tags:

views:

145

answers:

2

I have a few models, all with appropriately named model files.

$this->Property->PropertyImage->Image->read();

All linked accordingly. Problem is, the recursive model is not able to attach to all the relationships and for some reason is returning AppModel data type when i do a var_dump on $this->PropertyImage. When i do a var_dump($this->Property); i get data type: Property.

What is going on here, what would cause this to happen? Also how can I fix this problem?

A: 

Do you hava a PropertyImage model in your application or is it a HABTM association? If you're having a Property which hasAndBelongsToMany Image, you need a pivot table (properties_images) in the database, but to access Image model from the PropertiesController, you'd do $this->Property->Image without anything in between.

Marko
A: 

Building on what Marko said, if you have a HABTM relationship your best bet is to use a join table, properties_images.

Then rather than doing a Property->PropertyImage->Image, you would just do a Property->Image->read/find().

What I failed to understand about the HABTM relationship is how to filter based on criteria in the related model. E.g., you cannot do this:

$this->Property->Image->find( 'all', array( 'conditions' => array( 'Image.id' => 7 ) ) );

Instead, you have to add the Containable behavior to the Property model, as described in the manual at http://book.cakephp.org/view/474/Containable.

Travis Leleu