Module: Stannum::Entities::Associations::ClassMethods
- Defined in:
- lib/stannum/entities/associations.rb
Overview
Class methods to extend the class when including Associations.
Instance Method Summary collapse
-
#association(arity, class_or_name, **options) ⇒ Object
(also: #define_association)
Defines an association on the entity.
-
#associations ⇒ Stannum::Schema
The associations Schema object for the Entity.
-
#default_foreign_key_type ⇒ Class
The default type for foreign key attributes.
Instance Method Details
#association(arity, assoc_name, **options) ⇒ Symbol #association(arity, assoc_type, **options) ⇒ Symbol Also known as: define_association
Defines an association on the entity.
When an association is defined, each of the following steps is executed:
-
Adds the association to ::Associations and the .associations class method.
-
Adds the association to #association and the associated methods, such as #assign_associations, #[] and #[]=.
-
Defines reader and writer methods.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/stannum/entities/associations.rb', line 56 def association(arity, class_or_name, **) # rubocop:disable Metrics/MethodLength assoc_class = resolve_association_class(arity) assoc_name, assoc_type, = resolve_parameters(arity, class_or_name, ) association = associations.define( definition_class: assoc_class, name: assoc_name, type: assoc_type, options: (assoc_name, **) ) define_foreign_key(association) if association.foreign_key? association.name.intern end |
#associations ⇒ Stannum::Schema
Returns The associations Schema object for the Entity.
75 76 77 |
# File 'lib/stannum/entities/associations.rb', line 75 def associations self::Associations end |
#default_foreign_key_type ⇒ Class
Returns the default type for foreign key attributes.
80 81 82 |
# File 'lib/stannum/entities/associations.rb', line 80 def default_foreign_key_type (defined?(primary_key_type) && primary_key_type) || Integer end |