开发者

CakePHP read() not retrieving belongsTo bindings

I have a model called Voicenote with has a belongsTo relationship with Fonyker and ActivitySource. When I do the following:

function admin_index(){

        $this->layout = 'admin';
        $this->Voicenote->recursive = 2;

        $fields = array(
            'Voicenote.id',
            'Voicenote.title',
            'Voicenote.created',
            'Voicenote.duration',
            'Voicenote.public',
        );

        $this->paginate = array(
            'fields' => $fields,
            'limit' => 20,
            'order' =>开发者_开发问答 array('id' => 'ASC')
        );

        $result = $this->paginate('Voicenote');
        pr($result);
        $this->set('result', $result);
    }

The resulting array comes without Fonyker and ActivitySource, any ideas on what might be happening?

[0] => Array
        (
            [Voicenote] => Array
                (
                    [id] => 1
                    [title] => CFRFA5KBLPJZP79B2PG8XH8DFSMB8G
                    [created] => 2011-03-09 00:00:00
                    [duration] => 23868
                    [public] => 0
                )

            [Fonyker] => Array
                (
                )

            [ActivitySource] => Array
                (
                )

Also when I try using unbindModel() and unbind everything but Fonyker and ActivitySource they don't even show up as empty arrays.


I'm fairly new to CakePHP myself, but I think you have to have to define Fonyker and ActivitySource models as well? For example, put them in a hasOne or hasMany relationship.

Edit: Also, your $fields variable -- you don't seem to be selecting any values from Fonyker or ActivitySource.


Because you're using recursive = 2 and seeing empty Fonyker and ActivitySource arrays you're definitely querying those models, but your restrictive 'fields' means you're only going to get the fields you've listed.

You need to add the fields you need from Fonyker and ActivitySource into your fields array.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜