开发者

cakephp weird containable behavior

开发者 https://www.devze.com 2023-03-31 12:23 出处:网络
I am totally stuck now with containable behavior. In my model User everything works just fine and I get everything I need:

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
                     开发者_如何学Python               )
                            )
                    )
            )

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!


typo: contain, not contains

0

精彩评论

暂无评论...
验证码 换一张
取 消