title: Calling Class method via Rails ActiveRecord Association
body: <p>I have two classes as:</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    has_many :comments
  end
  
  class Comment &lt; ActiveRecord::Base
    belongs_to :post
  
    # Class method
    # does some analysis on all the comments of a given post  
    def self.do_sentiment_analysis
       post_id = self.new.post_id  # Is there a better way to get post_id?
  
       # real code that does something follows
  
    end
  
  end
  
  
  # Class method is called on a post object like this:
  Post.find(1).comments.do_sentiment_analysis
  </code></pre>
  
  <p>The question is whether there is a better way to know the id of the association object (post) on which the class method is called. One way (which is used above) is: <code>post_id = self.new.post_id</code>. 
  I bet there is a cleaner way where I don't have to create an object just to get the <code>post_id</code>.</p>