activerecord - YII: HAS_MANY Relation Issue -
yii newbie here.
i'm having issues one-to-many relation.
we have following tables:
## users uid username ## notes date body ## users_notes user_id note_id
we got 2 models - users:
'usersnotes' => array(self::has_many, 'usersnotes', 'user_id'),
and notes:
'usersnotes' => array(self::has_many, 'usersnotes', 'note_id'),
of course have model pivot table - users_notes:
return array( 'user' => array(self::belongs_to, 'users', 'user_id'), 'note' => array(self::belongs_to, 'notes', 'note_id'), );
when trying display notes in foreach loop we're getting error invalid argument supplied foreach()
in line foreach($this->_pkalias $name=>$alias)
of /framework/db/ar/cactivefinder.php(838)
file.
do have ideas? there we're missing/doing wrong?
if understood problem, have relation "one user has multiple notes". in case, don't need third table. notes needs 1 foreign key pointing user_id in users table.
in case need many many relation, tell us.
Comments
Post a Comment