CakePHP will not produce a join for hasMany and HABTM finds. As a
result, the fields of the associated table are not avaiable for the
query. There are a variety of techniques to get what you want.
There's the linkable behavior, ad-hoc join, and a method using
bindModel to bind the relationship as a hasOne to get CakePHP to do
the joins. These are discussed in the manual, on the bakery, and in
blogs.
On Jul 29, 9:45 pm, dean <hamish.dea...@gmail.com> wrote:
> Hi all,
>
> I'm having a slight problem with querying data on an association I've
> created.
>
> The two models are Product and ProductVariation. The ProductVariation
> model belongs to the Product model and the Product model hasMany
> ProductVariations.
>
> This is all well and good until I attempt to run the following query:
>
> $this->Product->find('all', array('conditions' =>
> array('ProductVariation.id' => 5)));
>
> I get a notice saying - SQL Error: 1054: Unknown column
> 'ProductVariation.id' in 'where clause'
>
> I don't understand, the models are associated and when I pull out a
> single product by its ID, the ProductVariation's are retrieved as
> well, but I cannot seem to get a condition bound to that column!
>
> Any insight would be greatly appreciated.
>
> Thanks in advance
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
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