I'm trying to figure out how to build a query with a condition that
effects the other Model in a HABTM relationship.
To clarify:
Let's say we have to models: Model1 and Model2 which are defined as
follows
var $hasAndBelongsToMany = array(
'Model2' => array('className' => 'Model2',
'joinTable' =>
'model1s_model2s',
'foreignKey' => 'model1_id',
'associationForeignKey' =>
'model2_id'
)
);
and let's assume that Model1 and Model2 both have the fields 'id' and
'name'
I'm trying to find all Model1s that are associated with a Model2 of a
certain name.
I'm trying to use the following query:
$m1s = $this->Model1->find('first',array('conditions' =>
array('Model2.name' => 'ddddd')));
Cake generates the following 2 queries from that
SELECT `Model2`.`id`, `Model2`.`name`, `Model1sModel2`.`model1_id`,
`Model1sModel2`.`model2_id`
FROM `model2s` AS `Model2` JOIN `model1s_model2s` AS `Model1sModel2`
ON ((`Model1sModel2`.`model1_id` IN (1, 2, 3)) AND
(`Model1sModel2`.`model2_id` = `Model2`.`id`))
and
SELECT `Model1`.`id`, `Model1`.`name` FROM `model1s` AS `Model1` WHERE
`Model2`.`name` = 'ddddd' LIMIT 1
which obviously generates the error 1054: Unknown column 'Model2.name'
in 'where clause'
I tried to go thtrough the core code and come up with a way to do this
but I'm running out of ideas.
I also wasn't able to tell from the manual how this is supposed to
work.
Any suggestions?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---