Module: Consort::Mongoid::ActiveRecord::ClassMethods
- Defined in:
- lib/consort/mongoid/active_record.rb
Instance Method Summary collapse
-
#belongs_to_active_record(klass) ⇒ Object
Defines a
belongs_torelationship with an ActiveRecord object. -
#has_many_active_record(klass) ⇒ Object
Defines a
has_manyrelationship with an ActiveRecord object. -
#has_many_active_records(klass) ⇒ Object
deprecated
Deprecated.
Use #has_many_active_record instead. Will be removed in 1.0.0.
-
#has_one_active_record(klass) ⇒ Object
Defines a
has_onerelationship with an ActiveRecord object. -
#mongoid_consorts_with_active_record? ⇒ Boolean
Allows easy validation of whether Mongoid to ActiveRecord bridge is loaded.
Instance Method Details
#belongs_to_active_record(klass) ⇒ Object
Defines a belongs_to relationship with an ActiveRecord object.
An appropriate foreign key field must exist on your model.
48 49 50 51 52 53 54 |
# File 'lib/consort/mongoid/active_record.rb', line 48 def belongs_to_active_record(klass) class_eval " def \#{klass}\n \#{klass.to_s.classify}.where(id: \#{klass.to_s.foreign_key})\n end\n CODE\nend\n" |
#has_many_active_record(klass) ⇒ Object
Defines a has_many relationship with an ActiveRecord object.
24 25 26 27 28 29 30 |
# File 'lib/consort/mongoid/active_record.rb', line 24 def has_many_active_record(klass) class_eval " def \#{klass}\n \#{klass.to_s.classify}.where(\#{name.foreign_key}: id)\n end\n CODE\nend\n" |
#has_many_active_records(klass) ⇒ Object
Deprecated.
Use #has_many_active_record instead. Will be removed in 1.0.0.
33 34 35 36 |
# File 'lib/consort/mongoid/active_record.rb', line 33 def has_many_active_records(klass) ActiveSupport::Deprecation.warn 'Please use the singular has_many_active_record instead.' has_many_active_record(klass) end |
#has_one_active_record(klass) ⇒ Object
Defines a has_one relationship with an ActiveRecord object.
11 12 13 14 15 16 17 |
# File 'lib/consort/mongoid/active_record.rb', line 11 def has_one_active_record(klass) class_eval " def \#{klass}\n \#{klass.to_s.classify}.where(\#{name.foreign_key}: id)\n end\n CODE\nend\n" |
#mongoid_consorts_with_active_record? ⇒ Boolean
Allows easy validation of whether Mongoid to ActiveRecord bridge is loaded.
58 59 60 |
# File 'lib/consort/mongoid/active_record.rb', line 58 def mongoid_consorts_with_active_record? true end |