I have standard users table. Every user can have many accounts
(account is a group of permissions, like a role) and every account can
be linked to many users. Relation is HABTM as you can see. When I
call:
$accounts=$this->User->find('first', array('conditions' => array
('User.user_id' => 1)));
i get:
Array ( [User] => Array ( [user_id] => 1 [contact_name] =>
Administrator [email_address] => [email protected] [username] => root
[password] => 7a89a595cfcjeb85480202a143e37d2e [language] => pl
[default_account_id] => 2 [comments] => [active] => 1 [sso_user_id] =>
[date_created] => 2009-08-13 18:45:50 [date_last_login] => 2009-08-17
14:33:27 [email_updated] => 2009-08-13 18:45:50 ) [Account] => Array
( ) )
Account array is empty. SQL generated by cake doesn't even mention
accounts or account_user_assoc table:
SELECT `User`.`user_id`, `User`.`contact_name`,
`User`.`email_address`, `User`.`username`, `User`.`password`,
`User`.`language`, `User`.`default_account_id`, `User`.`comments`,
`User`.`active`, `User`.`sso_user_id`, `User`.`date_created`,
`User`.`date_last_login`, `User`.`email_updated` FROM `ox2_users` AS
`User` WHERE `User`.`user_id` = 1 LIMIT 1
Can anyone help me with this?
My User model code:
class User extends AppModel {
var $name = 'User';
var $recursive=1;
var $hasAndBelongsToMany = array(
'Account' =>
array(
'className' => 'Account',
'joinTable' => 'account_user_assoc',
'foreignKey' => 'user_id',
'associationForeignKey' => 'account_id',
'unique' => true
)
);
function hashPasswords($data){
$data['User']['password']=md5($data['User']['password']);
return $data;
}
}
Account model code:
class Account extends AppModel {
var $name = 'Account';
var $primaryKey = 'account_id';
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---