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 subject
http://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 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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to