简体   繁体   中英

cakephp weird containable behavior

I am totally stuck now with containable behavior. In my model User everything works just fine and I get everything I need:

    $this->set(
        'user',
        $this->User->find(
            'first',
            array(
                'contain' => array('Ad', 'Ad.Placad', 'Ad.Placad.Place'),
                'conditions' => array('User.id' => $this->Auth->user('id'))
            )
        )
    );

outputs:

        Array
(
[User] => Array
    (
        [id] => 1
        [username] => admin
    )

[Ad] => Array
    (
        [0] => Array
            (
                [id] => 1
                [user_id] => 1
                [Placad] => Array
                    (
                        [0] => Array
                            (
                                [id] => 5
                                [ad_id] => 1
                                [place_id] => 1
                                [Place] => Array
                                    (
                                        [id] => 1
                                        [name] => kauf Bk
                                    )
                            )
                    )
            )

        [1] => Array
            (
                [id] => 2
                [user_id] => 1
                [Placad] => Array
                    (
                        [0] => Array
                            (
                                [id] => 6
                                [unique] => 1-2
                                [ad_id] => 2
                                [place_id] => 1
                                [Place] => Array
                                    (
                                        [id] => 1
                                        [name] => kauf Bk
                                    )
                            )
                    )
            )

But this one:

$this->set('ad',
        $this->Ad->find('first',
            array(
                'conditions' => array('Ad.id' => $id),
                'contains' => array('Placad', 'Placad.Place'),
            )
        )
    );

just ignores the Place table.

Array
(
[Ad] => Array
    (
        [id] => 1
        [user_id] => 1
        [name] => bota1
    )

[Placad] => Array
    (
        [0] => Array
            (
                [id] => 5
                [ad_id] => 1
                [place_id] => 1
            )

    )

)

There should be additional array with Place info in Placad, am I right? The first query is working, why the second one is broken? I hope the description provided is sufficient.

Thanks guys!

错字: contain ,不contains

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM