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

Restore support on saving `only` loaded documents

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 4.0.0 final
    • Fix Version/s: 6.0.0
    • Component/s: None
    • Labels:
      None

      Description

      I have some very large documents. Due to embedados and arrays fields.
      An example follows:

      {"_id" => BSON :: ObjectId ('5654b4b3204528cfa0000001'),
       "rating" => 1,
       "status" =>: ok,
       "bound_count" => 5,
       "group_ids" =>
        [BSON :: ObjectId ('55ba5d5420452896a8000007'),
         BSON :: ObjectId ('5602bf4c2045289107000001')]
      "events": [
      {"_id" => BSON :: ObjectId ('5654b4b3204528cfa0000002'),
          "field_a" =>: died,
          "field_b" => {},
          "EVENT_DATE" => 11.24.2015 19:04:19 UTC
          "trigger" => true,
          'type' =>: INLIST,
          "list_id" => BSON :: ObjectId ('5602bf4c2045289107000001'),
          "updated_at" => 11.24.2015 19:04:19 UTC
          "created_at" => 11.24.2015 19:04:19 UTC}
      ]}

      There may be hundreds of events and no more than ten group_ids for example.

      For my application I need some fields, but do not need the events.

      In version 3 Mongoid I filtered the necessary fields, performing my actions and alter some of these fields returned.

      entry = Model.without (: events) .first

      1. Logic of my application
        entry.rating = 3
        entry.status = :error
        entry.save
      2. raise Mongoid::Errors::ReadonlyDocument

      But Mongoid 4: "Documents now loaded from criteria using #only or #without will now raise an error When Attempting to save".

      I can not work it out with atomic operations. Because my model has callbacks (after_save, before_update) that depend on previous states of fields (ActiveModel :: Dirty).

      They can help me with any suggestions?

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              iagopimenta Iago
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: