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

Return Document#to_ary to be a private method

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.3.0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible

      In MONGOID-5009 (https://github.com/mongodb/mongoid/pull/4912), Document#to_ary was changed to be a public method. It's not clear to me why this change was made.

      This change breaks Active Model Serializers, a very widely used gem which is bundled with Rails in "API mode". In particular, AMS uses respond_to?(:to_ary) to determine whether the object being serialized is "array-like", i.e. whether a single or array serializer should be applied.

      Refer to the following lines:

      AMS Version 0.10: https://github.com/rails-api/active_model_serializers/blob/8f38571ed90e9ec245de59cccd2dbd8804c3bedf/lib/active_model/serializer.rb#L46

      AMS Version 0.8: https://github.com/rails-api/active_model_serializers/blob/0ef0f0c538f56b7608cf5103c32b74709ecff501/lib/active_model/serializer.rb#L270

      To fix this, we should revert Document#to_ary to be private, or consider removing it entirely.

      (I discovered this when I attempted to upgrade my app to Mongoid master.)

      I've raised a PR here: https://github.com/mongodb/mongoid/pull/4940

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: