And by the way, even not using the contain() method at all, and using the 'contain' array also in the Paper model does not help either: the contain on the Paper model breaks the contain on the AuthorsPaper model...

the only thing that works is to do a bindModel on the AuthorsPaper

$this->bindModel(array('hasOne'=>array(
        'Author'=>array(
        'type'=>'INNER',
        'foreignKey' => false,
        'conditions' => array('Author.id = AuthorsPaper.author_id')
))));
$joinAuthors = $this->find('all',
        array(
        'conditions' => array('AuthorsPaper.paper_id' => $id),
        'order' => 'AuthorsPaper.id'
        )
);

which is not "broken" by an earlier contain on the Paper model...

Lorenzo Bettini wrote:
It's just the same problem: if I do

$joinAuthors = $this->find('all',
    array(
    'contain' => array('Author'),
    'conditions' => array('AuthorsPaper.paper_id' => $id),
    'order' => 'AuthorsPaper.id'
    )
);

it still does not work, after the other contain call on Paper.

When it works (i.e., when it is called by itself) it correctly returns

Array
(
    [0] => Array
        (
            [AuthorsPaper] => Array
                (
                    [id] => 2
                    [author_id] => 3
                    [paper_id] => 2
                )

            [Author] => Array
                (
                    [id] => 3
                    [surname] => Bono
                    [name] => Viviana
                )

        )

    [1] => Array
        (
            [AuthorsPaper] => Array
                (
                    [id] => 3
                    [author_id] => 4
                    [paper_id] => 2
                )

            [Author] => Array
                (
                    [id] => 4
                    [surname] => Venneri
                    [name] => Betti
                )

        )

    [2] => Array
        (
            [AuthorsPaper] => Array
                (
                    [id] => 4
                    [author_id] => 2
                    [paper_id] => 2
                )

            [Author] => Array
                (
                    [id] => 2
                    [surname] => Bettini
                    [name] => Lorenzo
                )

        )

)

when it is called after calling a method on Paper's model class which does

$this->contain(array(
    'Author' => array(
        'AuthorsPaper',
        'order' => 'AuthorsPaper.id'
    )
));

then it returns only

Array
(
    [0] => Array
        (
            [AuthorsPaper] => Array
                (
                    [id] => 2
                    [author_id] => 3
                    [paper_id] => 2
                )

        )

    [1] => Array
        (
            [AuthorsPaper] => Array
                (
                    [id] => 3
                    [author_id] => 4
                    [paper_id] => 2
                )

        )

    [2] => Array
        (
            [AuthorsPaper] => Array
                (
                    [id] => 4
                    [author_id] => 2
                    [paper_id] => 2
                )

        )

)

thus that contain on the Paper model seems to break the later contain on the AuthorsPaper model...

cheers
    Lorenzo

Miles J wrote:
Add the contain into the find() itself, not a stand alone method.

'contain' => array('Author')

Can I see the array thats returned?

On Jan 8, 7:34 am, Lorenzo Bettini <[email protected]> wrote:
Hi

I've just started using the Containable behavior (which I put in AppModel).

I have Paper <-> Author, where <-> is the HABTM and in my AuthorsPaper
(join table related) model I have this method

function paper_authors($id) {
        $this->recursive = 0;
        $this->contain('Author');
        $joinAuthors = $this->find('all',
        array(
'conditions' => array('AuthorsPaper.paper_id' => $id), 'order' =>
'AuthorsPaper.id'
        )
        );

which retrieves the authors associated to a paper (without loading Paper
information).

This works perfectly.

But If I use this method after calling a method on Paper's model class
which does

$this->contain(array(
        'Author' => array(
                'AuthorsPaper',
                'order' => 'AuthorsPaper.id'
        )
));

the above method (paper_authors in class AuthorsPaper) does not work
anymore, meaning that it does not retrieve information about Author
anymore...

so does the method in Paper's class use of contain spoils any further
contain called on related classes (e.g., AuthorsPaper)?

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