I have a twitter style application whereby a user follows many people. This is achieved using a self-referential association.
This all works very nice but my brain has just gone dead while trying to figure out the active record syntax needed to list status updates (posts) from people the user follows ordered by time in a single query.
My user model looks like this
class User < ActiveRecord::Base
has_many :posts
has_many :friendships
has_many :friends, :through => :friendships
end
And the post model is
class Post < ActiveRecord::Base
belongs_to :user
end
For completeness the Friendship model
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, :class_name => "User"
end
Ultimately what I want to do is
@user.friends.reviews.all