Is there a way to retrieve from a model a list of new relation items added in a recent call to update_attributes

39 views
Skip to first unread message

Mike

unread,
Feb 16, 2017, 2:37:04 PM2/16/17
to Mongoid
Contrived Model:
class Hobby
  field :name
  belongs_to :person
end

class Person
  has_many :hobbies
  accepts_nested_attributes_for :hobbies
end

Scenario:
I have a form that allows a user to add multiple hobby objects by calling #update_attributes on the retrieved person object to do this. How do I ascertain what new Hobby objects were added by my call to #update_attributes? Is there a helper which identifies these new objects in the person.hobbies Proxy? A use case (not mine, but proves the usefulness) would be to show a flash message saying "Added Hobby X and Hobby Y as Hobbies".


Reply all
Reply to author
Forward
0 new messages