I’m using cakephp 1.3 with mysql database and engine is MYISAM, I’m getting problem in relationships. I have two tables name Organization and OrgClasses, these two are associated with mbo_studio_id which is common in both table.
organization
Id(PK), name, mbo_studio_id
org_classes
id(PK), name,date, mbo_studio_id
I’m trying to fetch data on the condition of mbo_studio_id, but it adds another condition by primary key of OrgClasses.
var $belongsTo = array(
'OrgClass' => array(
'className' => 'OrgClass',
'foreignKey' => 'mbo_studio_id',
'conditions' => array('OrgClass.mbo_studio_id' => 'Organization.mbo_studio_id'),
'order' => 'OrgClass.date DESC',
'dependent' => false,
)
);
I get following query
SELECT `Organization`.`id`, `Organization`.`name, `Organization`.`mbo_studio_id`, `OrgClass`.` id`,`OrgClass`.`mbo_studio_id`, `OrgClass`.`name`, `OrgClass`.`date`
FROM `organizations` AS `Organization`
LEFT JOIN `org_classes` AS `OrgClass` ON (`Organization`.`mbo_studio_id` = `OrgClass`.`id` AND `OrgClass`.`mbo_studio_id` = Organization.mbo_studio_id)
Here I don’t want Organization.mbo_studio_id = OrgClass.id condition in query.
Thanks
Then you need to set foreignKey to false:
This way it will only use your custom conditions.