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