I have 2 models Item and Defect.
both of them have description.
an Item can have many Defects and my defects table has a an item_id
field.
Now I'm trying to create a search query that will search both the item
description and the defect description.
What I do is this:
$this->Item->bindModel(
array('hasMany' => array(
'Defect' => array(
'className' => 'Defect',
'foreignKey' => 'item_id',
'type' => 'INNER'
)
)
)
);
then I run findAll.
Now when I use findAll with no conditions everything works fine. cake
seems to run 2 queries:
SELECT `Item`.`id`,...... FROM `items` AS `Item` WHERE 1 = 1
SELECT `Defect`.`id`,.......... FROM `defects` AS `Defect` WHERE
`Defect`.`item_id` IN (1, 2, 16, 15, 14, 13, 12, 11, 10, 17, 18, 19,
20)
My first question is why does cake doesn't create one query with INNER
JOIN?
The second problem is when I add conditions:
$conditions[] = "`Item`.`name` LIKE '%" .$search_term ."%' OR
`Defect`.`description` LIKE '%" . $search_term . "%'";
It seems that cake in this case ignores the join all together and just
does a regular select so I get an error:
1054: Unknown column 'Defect.description' in 'where clause'
Does anyone know what I'm doing wrong?
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment