Complicted ActiveRecord Association. Going through a 4th table
- by Dex
I have kind of a complicated case and am wondering how this would work in rails:
I want to categories the genres of some singers. Singers can belong to more than one genres, and users can assign tags to each genre
For example:
singers <-- singers_genres -- genres <-- genres_tags -- tags
SQL would look something like:
SELECT * FROM singers S
INNER JOIN singers_genres SG ON S.id=SG.singer_id
INNER JOIN genres G ON G.id = SG.genre_id
LEFT OUTER JOIN genre_tags GT ON G.id = GT.genre_id
INNER JOIN tags T ON GT.tag_id = T.id