Hi

I have Paper and Author in HABTM relation (AuthorsPaper is the join 
table model).

If I try to perform a find on the Paper model which involves also the 
authors in the condition I get an error since only the papers table is 
used for the conditions (even though recursive is set to 1).

Thus, I made an explicit join:

$joins[] = array(
'table' => $this->AuthorsPaper->tablePrefix.$this->AuthorsPaper->useTable,
'alias' => 'AuthorsPaper',
'conditions' =>
array('AuthorsPaper.paper_id = Paper.id AND AuthorsPaper.author_id' => 
$authors)
);

$this->find('all',
array(
'joins' => $joins,
'conditions' => $conditions
)
);

where $conditions includes conditions on papers' fields.

Is this the correct approach?

In particular, I haven't found any "official" documentation on joins but 
on some blog posts or on bakery (e.g., 
http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-in-model-find).

I'm asking since using joins requires specifying an explicit table name 
(which can be achieved anyway using tablePrefix and useTable so that it 
works also with fixtures in unit tests).

thanks in advance
        Lorenzo

-- 
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com

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