I was told that to accomplish mapping the $belongsTo to a non primary key, I would set the foreignKey to false and set the conditions by someone on another forum (IRC, actually). However, I don't think I'm doing this correctly. Below is my $belongsTo code I was trying:
var $belongsTo = array(
'Inventory' => array(
'className' => 'Inventory',
'foreignKey' => false,
'conditions' => array('RentalLineitem.i_num' => 'Inventory.i_num'),
'dependent' => false
)
);
When I look at the SQL query that's being generated, the 开发者_如何学GoON clause in the JOIN is looking for the string value instead of the column: `RentalLineitem`.`i_num` = 'Inventory.i_num' instead of what I need which is `RentalLineitem`.`i_num` = `Inventory`.`i_num`.
I've been told to change the "just change the database schema" to be correct. However, this is a legacy application, the database already has existed for 10 years, and there are other applications using this database. I HAVE to work with the tables I have, and I can not change the schema.
How can I properly associate these models?
hmm this might not be the correct way, but i already had some similar problems and i corrected it by doing something like:
'conditions' => array(' `RentalLineitem`.`i_num` = `Inventory`.`i_num`'),
hope this helps,
Good Luck
You just edit in conditions like that:
'conditions' => array(
'RentalLineitem.i_num = Inventory.i_num',
),
It works correctly in my case.
精彩评论