http://teknoid.wordpress.com/2008/07/17/forcing-an-sql-join-in-cakephp/

Lapinski


ohneworte-2 wrote:
> 
> 
> Hello Together,
> I want to link two Models without using a Foreign Key, but using some
> Conditions instead. Here is my example:
> 
> Model:
> ---------
> class Category extends AppModel {
>       var $name = "Category";
>       var $actsAs = array("Containable");
> 
>       var $hasMany = array(
>               "Zone" => array(
>                       "foreignKey" => false,
>                       "conditions" => array(
>                               "AND" => array("Category.width = Zone.width", 
> "Category.height =
> Zone.height")
>                       )
>               )
>       );
> }
> 
> Controller:
> --------------
> $category = $this->Category->find("first", array(
>       "conditions" => array("Category.id" => 1),
>       "contain" => array(
>               "Zone"
>       )
> ));
> 
> Result:
> ----------
>>>SQL Error: 1054: Unknown column 'Category.width' in 'where clause'<<
> 
> That seems clear if you make a look on the generated Query:
>>>SELECT ... FROM 'zones' AS 'Zone' WHERE (('Category'.'width' =
'Zone'.'width') AND ('Category'.'height' = 'Zone'.'height')) <<
> 
> No Join occurs - but why? Can anybody help me out?
> I appreciate any help on this issue.
> 
> Regards.
> > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Model-Association-via-%22conditions%22-fails%21-tp23213390p24621578.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
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