0

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',
        'required' => 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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Dominik Kukacka
  • 569
  • 1
  • 5
  • 15
  • 1
    How are you retrieving the array? If you're talking about the $_SESSION['Auth']['User'] array, note that it's only set on login, and does not include the related models. If you print_r( $this->User->find(...) ), it should show the attached Meta information. – Travis Leleu Apr 12 '10 at 19:24
  • yeah with the $this->User->find i get all the meta data now I want to get the eta data from the current loggedin user :) (in every controller...) what is the best way to do this? greetz – Dominik Kukacka Apr 13 '10 at 19:20

2 Answers2

0

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

Young
  • 7,986
  • 7
  • 43
  • 64
0

Have you tried:

$currentUserData = $this->User->read(null,$this->Auth->user('id'));
Leo
  • 6,553
  • 2
  • 29
  • 48