Monday, May 30, 2011

Re: Find with $hasAndBelongsToMany

I've just posted a similiar query!

Googling around has given me the bindModel() method - which you can
read at the bottom of the page here:

http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM

But I wasn't able to get it to work for me. There's also a method
using manual joins and creating models for the join table and querying
it - haven't tried either of the two and can't say if they'll work.

On May 30, 5:14 pm, hill180 <hill...@gmail.com> wrote:
> I have three models
> Authors
> Books (hasandbelongstomany category)
> Category
>
> They are properly configured for $hasAndBelongsToMany (books/category)
> relationship.
>
> I need to get all books by an author in a certain category (5 in this
> example)
>
> Obviously the category id is not in the authors table so I am trying to
> figure out how to reference the category id.  I have tried below to no
> avail.
>
> $this->Category->Author->find('all',
> array('conditions'=>array('Category.id'=>'5', 'Author.id'=>'2')));
> or
> $this->Author->find('all', array('conditions'=>array('Category.id'=>'5',
> 'Author.id'=>'2')));
>
> This is the first time I have done a HABTM query.  (searched manual and and
> a couple cake books - no help)
>
> Thanks!

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: