Module: Mongoid::Max::Denormalize::ClassMethods
- Defined in:
- lib/mongoid/max/denormalize.rb
Instance Method Summary collapse
- #denormalize(relation, *fields) ⇒ Object
- #denormalize_update_all(conditions, updates) ⇒ Object
- #mongoid2 ⇒ Object
- #mongoid3 ⇒ Object
Instance Method Details
#denormalize(relation, *fields) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mongoid/max/denormalize.rb', line 13 def denormalize(relation, *fields) = fields. #TODO make all real fields if fields.empty? # puts "#relation : #{relation.inspect}" # puts "#fields : #{fields.inspect}" # puts "#options : #{options.inspect}" = self.relations[relation.to_s] raise ConfigError.new("Unknown relation", self, relation) if .nil? # puts "# meta : #{meta.inspect}" = .klass.relations[.inverse.to_s] raise ConfigError.new("Unknown inverse relation", self, relation) if .nil? # puts "#inverse_meta : #{inverse_meta.inspect}" if .relation == Mongoid::Relations::Referenced::In && .relation == Mongoid::Relations::Referenced::Many OneToMany.new(self, , , fields, ).attach elsif .relation == Mongoid::Relations::Referenced::Many && .relation == Mongoid::Relations::Referenced::In ManyToOne.new(self, , , fields, ).attach else raise ConfigError.new("Relation not supported", self, relation) end end |
#denormalize_update_all(conditions, updates) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/mongoid/max/denormalize.rb', line 48 def denormalize_update_all(conditions, updates) if mongoid3 self.collection.find(conditions).update_all(updates) else self.collection.update(conditions, updates, :multi => true) end end |
#mongoid2 ⇒ Object
44 45 46 |
# File 'lib/mongoid/max/denormalize.rb', line 44 def mongoid2 Mongoid::VERSION =~ /\A2\./ end |
#mongoid3 ⇒ Object
41 42 43 |
# File 'lib/mongoid/max/denormalize.rb', line 41 def mongoid3 Mongoid::VERSION =~ /\A3\./ end |