mongoid
mongoid copied to clipboard
MONGOID-5210 Prefer field :type as Symbol + custom field type symbols
This is blocked until after https://github.com/mongodb/mongoid/pull/5269 is merged.
Fixes MONGOID-5210
Prior to this PR, Mongoid already supports defining field :type as a Symbol rather than a Class:
field :first_name, type: :string # works today, even without this PR!
Generally speaking, it is much better to to use Symbol than Class, because Class uses autoloading etc.
This PR adds the following:
- Main documentation is updated to prefer using Symbol rather than Class. I haven't done this change in 100% of doc files; I plan to do that after this PR is merged in a separate PR.
- Usage of Class is deprecated and now logs a warning. Usage of Class is intended to be removed in Mongoid 8.0.
- It is now possible to define custom symbols using the following:
Mongoid::Fields.configure do
type :point, Point
end
Further Plans
In Mongoid 8.1+, once everything is symbols we should consider extracting out the mongoization logic into separate modules and not inserting methods into Ruby Kernel classes. For example, String.mongoize should be Mongoizers::String.mongoize(string).
@p-mongo tests are now written. This is ready for final review and merge.
@p-mongo I will be happy to split out that code soon. However, please see my reply in https://jira.mongodb.org/browse/MONGOID-5210, in the future, I still believe there is strong justification to switch to symbols.
@p-mongo PR split out, please see: https://github.com/mongodb/mongoid/pull/5269