@heimdull, wow I search and learn "searchlogic" and it's very very logic and super duper easy, thanks. (sorry, mistype)
On Aug 26, 10:46 pm, Geekyra <gkr...@gmail.com> wrote: > 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. :) > > On Aug 26, 5:23 pm, Mukund <marut...@yahoo.com> wrote: > > > Make it a named_scope instead of a function so that it can be chained > > in the future. > > > Class Post > > named_scope :other_users_posts, lambda { |user_object| {:conditions=> > > ["user_id <> ?", user_object.id]}} > > end > > > You can then do a Post.other_users_post(User.first) as an example and > > chain it just like other active record finder functions. > > > On Aug 26, 1:33 am, Geekyra <gkr...@gmail.com> wrote: > > > > Hi All, > > > > 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 > > > willfindposts 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 : > > > > @posts = Post.find_other_user_posts > > > > will return collection of C, D, F posts. > > > > Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---