Module: Mongoid::Hierarchy::ClassMethods
- Defined in:
- lib/mongoid/hierarchy.rb
Instance Method Summary collapse
-
#hereditary? ⇒ true, false
Determines if the document is a subclass of another document.
-
#inherited(subclass) ⇒ Object
When inheriting, we want to copy the fields from the parent class and set the on the child to start, mimicking the behaviour of the old class_inheritable_accessor that was deprecated in Rails edge.
Instance Method Details
#hereditary? ⇒ true, false
Determines if the document is a subclass of another document.
154 155 156 |
# File 'lib/mongoid/hierarchy.rb', line 154 def hereditary? Mongoid::Document > superclass end |
#inherited(subclass) ⇒ Object
When inheriting, we want to copy the fields from the parent class and set the on the child to start, mimicking the behaviour of the old class_inheritable_accessor that was deprecated in Rails edge.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/mongoid/hierarchy.rb', line 168 def inherited(subclass) super @_type = nil subclass.aliased_fields = aliased_fields.dup subclass.localized_fields = localized_fields.dup subclass.fields = fields.dup subclass.pre_processed_defaults = pre_processed_defaults.dup subclass.post_processed_defaults = post_processed_defaults.dup subclass._declared_scopes = Hash.new { |hash,key| self._declared_scopes[key] } subclass.autosaved_relations = autosaved_relations.dup # We only need the _type field if inheritance is in play, but need to # add to the root class as well for backwards compatibility. unless fields.has_key?("_type") field(:_type, default: self.name, type: String) end subclass_default = subclass.name || ->{ self.class.name } subclass.field(:_type, default: subclass_default, type: String) end |