Non Working Relationship
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'));
精彩评论