I have 3 models: Users, Articles and Comments.
- Articel has many Comments.
- Comments belongs to Article.
- User has many comments.
Textbook case 🙂
I would like to make a list of Article IDs where the User has made Comments on. How do I do that?
I’ve tried variants of User.find(1).comments.articles_ids in the console but that gives me a undefined method error.
I’m sure it’s simple, but I cant’t figure it out 🙂
Thanks!
One way of doing it, that works with your current setup:
Alternatively I guess you could add a
has_many :throughtoUser:then you can get the ids via
user.articles.collect(&:id)(perhaps alsouser.article_ids, but I’m not sure about that).