php - Two associations for the same table resulting in a collision -
i have videos
, artists
, video belongsto
artist , artist hasmany
videos.
i did , working, when find videos
, set [contain => ['artists']
got result videos entity related artist.
this first relationship artist "owner" of video, need relationship because video have n
others artists "featuring" video.
heres better overview:
tables:
videos: id (pk), artist_id (fk)
artists_videos: video_id (pk), artist_id (pk)
artists: id (pk)
-
heres code:
//videostable $this->belongsto('artists'); $this->belongstomany('artists'); //artiststable $this->hasmany('videos'); $this->belongstomany('videos');
the issue is, when set second relationship first relationship stops work, think happening kind of collision.
you need call these associations different names:
$this->belongsto('comments', [ 'classname' => 'comments', ... ]); $this->hasmany('unapprovedcomments', [ 'classname' => 'comments', ... ]);
... they're treated orm separate instances.
Comments
Post a Comment