Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4056

calling assign_attributes updates has many nested relations

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None

      my model in short:

      class Event
        ...
        has_many :dates, class_name: 'EventDate'
        accepts_nested_attributes_for :dates, allow_destroy: true
        ...
      end
      

      when i perform assign_attributes modifying some data like this (the time has changed for date at index 0):

      params = { "dates_attributes"=>{"0"=>{"starts_at"=>"2015-04-30 20:01", "_destroy"=>"0", "id"=>"553a063469702d0741050000" }}}
      event.assign_attributes params
      

      the change is persisted to the database which is unexpected

      MOPED: 127.0.0.1:27017 UPDATE       database=xxxx_development collection=event_dates selector={"_id"=>BSON::ObjectId('553a063469702d0741050000')} update={"$set"=>{"starts_at"=>2015-04-30 18:01:00 UTC}} flags=[]
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            AlexandreBernard AlexandreBernard [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: