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

don't populate .changed_attributes setting has_and_belongs_to_many association

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.0.1
    • Affects Version/s: 7.0.5
    • Component/s: Attributes
    • Labels:
      None
    • Environment:
      Linux, Rails 6.0.2.1
    • Minor Change

      As per my comments below I believe the work that should be done in this ticket is actually opposite of the requested changes. This ticket originally was to add the changing of the HABTM association to the changes hash, however I believe the correct way to proceed is to remove that change from the changed_attributes hash. (See my comments below for a longer discussion of why that is)

      Original ticket:

      tether-it(test)> user.timelines = [t1, t2]

      tether-it(test)> user.changed?

      => false

      tether-it(test)> user.changes

      => {}

      tether-it(test)> user.changed_attributes

      => {"timeline_ids"=>[BSON::ObjectId('5e481d75e23a26c32d8cb4fe'), BSON::ObjectId('5e481d75e23a26c32d8cb4ff')]}

      The expected results would be for .changes to show: "timeline_ids" => [[], [t1.id, t2.id]]

      The code in the model is:

      has_and_belongs_to_many :timelines,

               inverse_of: nil, validate: false, index: true

      validate :assigned_timelines, on: :update, if: :timeline_ids_changed?

      Any ideas?

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            roman@tetherit.io Roman Gaufman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: