-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
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
- is caused by
-
MONGOID-5009 Belongs to relationship makes all target association methods effectively public
- Backlog