开发者

Non Working Relationship

开发者 https://www.devze.com 2022-12-26 07:32 出处:网络
I got a problem with cake\'s model architecture. I got a Users-Model and a Metas-Model. Here are the model codes:

I got a problem with cake's model architecture.

I got a Users-Model and a Metas-Model. Here are the model codes:

Users:

<?php
class User extends AppModel {

var $name = 'User';
var $validate = array(
    'username' => array('notempty'),
    'email' => array('email'),
    'password' => array('notempty')
);
    var $displayField = 'username';


var $hasMany = array(
        'Meta' => array(
            'className' => 'Meta',
            'foreignKey' => 'user_id'        
        )
);

}
?>

and the Metas Model:

<?php
class Meta extends AppModel {

var $name = 'Meta';

//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
    'User' => array(
        'className' => 'User',
        'foreignKey' => 'user_id',
        'requi开发者_C百科red' => true
    )
);

}
?>

So now the question is why do I not get the Meta data into the User array? Should I get it in the Auth object?

Or where can I work with the meta data?


Your models seem to be fine.The problem must be in your controller file.See Retrieving data and hasMany relation in the cookbook.


Have you tried:

$currentUserData = $this->User->read(null,$this->Auth->user('id'));
0

精彩评论

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