Thursday, 15 May 2014

ruby on rails - Get unsaved associations from inside the model -


How can I use associations saved from within a model method? For example:

  class post  comments  

The method already called within a model method Only the associations have been saved When I call the method from the object, eg Post Comments This gives both saved and unsaved organizations.

How can I use saved and saved associations from within a model method?

How about something like this?

  class posts & lt; ActiveRecord :: Base is has_many: comments def comments_dates comments.pluck (: created_at) .sort end def comments_dates_no_query comments.map (& created_at) .sort end def unsaved_comments comments.reject (&: continu?) End def saved_comments Comments < / Code> 

You can like us at

  post.saved_comments  

  Post.unsaved_comments  

Hope that helps!


No comments:

Post a Comment