Hello fellow developers! Recently I've been playing with Rails 3.0 and after quite a bit of research I'm kinda stuck. I want to know what approach or solution is the best in my case(I couldn't find an answer yet). So what I'm trying to achieve is simple and straight forward.
I want to do something like this:
class User < ActiveRecord::Base
has_many :feeds
has_many :casts, :through => :feeds
end
class Feed < ActiveRecord::Base
has_many :users
has_many :casts
end
class Cast < ActiveRecord::Base
belongs_to :feed
end
So at the end I need to have methods like User.first.feeds to get all the user's feeds and User.first.casts to get all the user's casts through his/her feeds. Also would be nice to have Feed.first.casts and Feed.first.users. Pretty simple, right, but I'm also having a hard time to create migrations for what I'm trying to achieve.
I know that the code above won't work - I've been playing with it so this is just the concept of what I'm trying to achieve.
Basically my questions are: should I do it through join model somehow or use scopes?(also could you give a code snippet) and how do I do migration for that?
Thanks, and sorry I couldn't find much information on the web regarding this simple case.
Edit: has_and_belongs_to_many on User and Feed won't work in my case because it won't allow me to have @user.casts, it gives only @user.feeds and @feed.users