If you want that to be a class method on Post you'll have to pass in
the id of the user I think.

How about something like:

  def self.find_other_users_posts(this_user)
    self.find(:all, :conditions => ["user_id <> ?", this_user.id])
  end

HTH,

-Roy

On Aug 25, 1:33 pm, 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
> 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 :
>
> @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
-~----------~----~----~----~------~----~------~--~---

Reply via email to