Module: Superstore::Associations::ClassMethods
- Defined in:
- lib/superstore/associations.rb
Instance Method Summary collapse
-
#belongs_to(name, options = {}) ⇒ Object
Options [:class_name] Use if the class cannot be inferred from the association [:polymorphic] Specify if the association is polymorphic Example: class Driver < Superstore::Base end class Truck < Superstore::Base end.
- #generated_association_methods ⇒ Object
- #has_many(name, options = {}) ⇒ Object
- #has_one(name, options = {}) ⇒ Object
Instance Method Details
#belongs_to(name, options = {}) ⇒ Object
Options
- :class_name
-
Use if the class cannot be inferred from the association
- :polymorphic
-
Specify if the association is polymorphic
Example:
class Driver < Superstore::Base
end
class Truck < Superstore::Base
end
21 22 23 |
# File 'lib/superstore/associations.rb', line 21 def belongs_to(name, = {}) Superstore::Associations::Builder::BelongsTo.build(self, name, ) end |
#generated_association_methods ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/superstore/associations.rb', line 33 def generated_association_methods @generated_association_methods ||= begin mod = const_set(:GeneratedAssociationMethods, Module.new) include mod mod end end |
#has_many(name, options = {}) ⇒ Object
25 26 27 |
# File 'lib/superstore/associations.rb', line 25 def has_many(name, = {}) Superstore::Associations::Builder::HasMany.build(self, name, ) end |
#has_one(name, options = {}) ⇒ Object
29 30 31 |
# File 'lib/superstore/associations.rb', line 29 def has_one(name, = {}) Superstore::Associations::Builder::HasOne.build(self, name, ) end |