HABTM and belongsTo at the same join, cakePhp

Posted by Cynthia on Stack Overflow See other posts from Stack Overflow or by Cynthia
Published on 2011-02-17T20:00:15Z Indexed on 2011/02/17 23:25 UTC
Read the original article Hit count: 348

Filed under:
|
|
|

Hello everyone.

I have a model Fix with a relationship HABTM Device model. Device model has a belongsTo to Device_type model, like this, for only getting the device type name:

var $belongsTo = array('Device_type'=>array('fields'=>'name'));

So, I need every Fix, its devices and its Device_types. When I make a Fix->find('all', array('recursive' => 2)) I expect to get every Device related to Fix (this works ok) and ALSO for every device, its Device_type.name (which is not working). This is what I get instead for every Device in the result (an empty array):

["Device_type"]=>
    array(0) {
}

Besides this, when I make this query for testing: Fix->Device->find('all'), it returns the current Device_type.names for every device related to fixes, which means models are related propertly.

Any help? Thanks.

© Stack Overflow or respective owner

Related posts about cakephp

Related posts about cakephp-1.3