0

基本上我有三个模型歌曲、播放列表和作业。

歌曲通过分配有许多播放列表,反之亦然。

我想编写一个查询来查找包含指定歌曲的每个播放列表。假设这首歌是由@song 指定的。

到目前为止,我有:

#find all the assignments that contain a song_id 

@commonAssignments = Assignment.where("song_id = ?", @data)
@commonPlaylists = #code to find playlists which contain any of the assignments found here

我想知道从这里去哪里,提前感谢您的帮助

4

1 回答 1

0
#create an array of strings made up of playlist id's

@commonAssignments = Assignment.select(:playlist_id).where("song_id = ?", @data).map &:setlist_id

#then find all records associated
    @commonPlaylists = Playlist.find(@commonAssignments)
于 2012-07-20T11:07:29.973 回答