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

calling assign_attributes updates has many nested relations

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Gone away
    • Affects Version/s: None
    • Fix Version/s: 12_01_17
    • Component/s: None
    • Labels:

      Description

      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=[]
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: