help – foreign key, backjoint between 3 tables

winman1
Member | 10
+
0
-

hi guys,

i have table youtube_channel_playlist with 2 foreign keys to 2 other tables youtube_channel and youtube_playlist:

CONSTRAINT FK_channel_playlist__channel_id FOREIGN KEY (channel_id) REFERENCES youtube_channel (channel_id) ON UPDATE CASCADE,
CONSTRAINT FK_channel_playlist__playlist_id FOREIGN KEY (playlist_id) REFERENCES youtube_playlist (playlist_id) ON UPDATE CASCADE

when i try fetch all rows from youtube_channel_playlist with parameter $dbChannelId:
$rows = $this->database->table(‘youtube_playlist’)
->select(‘youtube_playlist.playlist_id’)
->select(‘youtube_playlist.yt_playlist_id’)
->select(‘youtube_playlist.yt_playlist_title’)
->where(‘:youtube_channel_playlist.youtube_channel.channel_id’, $dbChannelId)

I allways get such the error:
No reference found for $youtube_channel_playlist->youtube_channel

seems Nette understand “:youtube_channel_playlist” for relationship youtube_playlist to youtube_channel_playlist
but it does not understand next “.” in “youtube_channel_playlist.youtube_channel”

Please could you give an advance? Many thanks.

filsedla
Member | 101
+
+1
-

Hello, try one of these:

->where(':youtube_channel_playlist.channel.channel_id', $dbChannelId)

or just

->where(':youtube_channel_playlist.channel_id', $dbChannelId)

They should both be equivalent and do what you want.

winman1
Member | 10
+
0
-

dear filsedla,

thanks for hint! so joining 2 tables works.

But in my case we still have problem with joining tables via “:” and then “.” :)