Hello,

I have the following models / relations:

<?php
class Service extends AppModel {
    var $useTable = 'service';
    var $belongsTo = array('ServiceGroup', 'ServiceType');
}
?>

<?php
class ServiceType extends AppModel {
    var $useTable = 'service_type';
    var $hasMany = array(
        'Service',
        'ServiceTypeField' => array(
            'dependent' => true
        ));
}
?>

<?php
class ServiceTypeField extends AppModel {
    var $useTable = 'service_type_field';
    var $belongsTo = array('ServiceType');
    var $hasMany = array(
        'ServiceTypeFieldValue' => array(
            'dependent' => true
        ));
}
?>

<?php
class ServiceTypeFieldValue extends AppModel {
    var $useTable = 'service_type_field_value';
    var $belongsTo = array('ServiceTypeField');
}
?>

in Service controller, I want to query all ServiceTypeFields and
related ServiceTypeFieldValues with certain Service id. So I tried
this:

$service_id = 1;
$params = array(
    'conditions' => array('Service.id' => $service_id),
    'order' => array('Service.name'),
);
$serviceTypeFieldList = $this->Service->ServiceType->ServiceTypeField-
>find('all', $params);

that generates the followin SQL:

Query: SELECT `ServiceTypeField`.`id`,
`ServiceTypeField`.`service_type_id`, `ServiceTypeField`.`name`,
`ServiceType`.`id`, `ServiceType`.`name` FROM `service_type_field` AS
`ServiceTypeField` LEFT JOIN `service_type` AS `ServiceType` ON
(`ServiceTypeField`.`service_type_id` = `ServiceType`.`id`)  WHERE
`Service`.`id` = 1   ORDER BY `Service`.`name` ASC

and that does not work as the Service table isn't bound to the
relations and it cannot find Service.id or Service.name. What I'm
doing wrong? How can I tell cake to join Service to the find too?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to