I have 3 model, User, Post, Comment with definition like below
class Post < ActiveRecord::Base
belongs_to :user
has_many :comments
def self.find_other_user_posts
?
end
end
class User < ActiveRecord::Base
has_many :posts
has_many :comments
has_many :posts_commented_on, :through => :comments, :source
=> :posts
end
class Comment< ActiveRecord::Base
belongs_to :post
belongs_to :user
end
User can have many post and many comment, question is I want to make
method in Post model that returning collection of posts. The method
will find posts and comments that doesn't belong to current user. For
example there are
Post: A have Comment: A1
Post: B have Comment: B1, B2, B3, B4
Post: C have Comment: C1, C2
Post: D have Comment: nil
Post: E have Comment: nil
Post: F have Comment: F1, F2, F3
current user own Post A, E and Comment A1, B2, so calling :
Ah, @Roy, sorry but the solution doesn't work.
The question is to return C, D, F because current user doesn't own C,
D, F, and current user doesn't make any comment on C, D, F.
Actually there are 2 condition I want to achieve, I want to return
collection of post that :
1. Other than my own post OR Haven't read it yet OR Post not created
by me.
2. And Post that haven't got my Comment at all because if I'm already
make a Comment on a Post then it assume that I'm already read the post
before.
So what I want is a Post that is very very new to me and I want to
read it and make Comment. How to do that ?
@Roy, wow I search and learn "searchlogic" and it's very very logic
and super duper easy, thanks.
@Mukund, hanks for named_scope suggestion I search the article and
learn it and found out IT'S VERY COOL, especially the chain part.