Thanks Paul,

I'll give it a go.

You're right - the teknoid.wordpress.com site has a good bunch of
HABTM stuff on it, in particular:
http://teknoid.wordpress.com/2008/08/06/habtm-and-join-trickery-with-cakephp/

I think what I'm really missing is more detail on the various
parameters you can stick into find(). In your example, you've used
DISTINCT and OR and in the linked-to article they use 'group'. Where
are these coming from? Am I missing this as I'm new to SQL in general?
The book isn't exactly detailed in this area...

Thanks a lot,
Jeremy

On May 10, 5:38 pm, WebbedIT <p...@webbedit.co.uk> wrote:
> Firstly, welcome to the community and to the joys of CakePHP
>
> Secondly, HABTM is where a lot of people tend to start tripping over
> themselves as it's really a convenience method to join 3 tables
> together with minimal coding and doesn't always have the flexibility
> of what should ideally be a
>
> ModelA hasMany JoinModel
> ModelB hasMany JoinModel
> JoinModel belongsTo ModelA
> JoinModel belongsTo ModelB
>
> The book touches on finding recipes by tag very lightly on 
> page:http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM
>
> However to really get my head around HABTM I spent some time reading
> Teknoids articles on the subjecthttp://teknoid.wordpress.com/?s=habtm
>
> He also created a Habtamable behaviour which I am yet to try using
> myself:http://teknoid.wordpress.com/2009/09/26/habtamable-behavior/
>
> The book example gives you a couple of examples of how to fetch data
> relating to a certain tag and Teknoid expands on those.
>
> I think from what you are saying and looking at the book's example you
> should be able to get close to what you want by using
>
> $this->Article->Tag->find('all', array('conditions'=>array(
>   'OR'=>array(
>     'Tag.name'=>'Tag1',
>     'Tag.name'=>'Tag2',
>     'Tag.name'=>'Tag3'
>   )
> )));
>
> Grouping your conditions in an OR array will fetch any article that
> matches any of the tags rather than all of them, but then you will
> have to tackle the problem that this will not fetch UNIQUE articles.
> You will have to experiment with something along the lines of
>
> $this->Article->Tag->find('all', array(
>   'fields'=>array('DISTINCT Article.id', 'Article.title',
> 'Article.???')
>   'conditions'=>array(
>     'OR'=>array(
>       'Tag.name'=>'Tag1',
>       'Tag.name'=>'Tag2',
>       'Tag.name'=>'Tag3'
>   ))
> ));
>
> Hope this helps,
>
> Paul
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.com For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to