Module: Railsmith::BaseService::AssociationDsl::ClassMethods
- Defined in:
- lib/railsmith/base_service/association_dsl.rb
Overview
Class-level DSL macros for declaring relationships on a service.
Instance Method Summary collapse
-
#association_registry ⇒ Object
Returns the AssociationRegistry for this class.
- #inherited(subclass) ⇒ Object
-
#link_many(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) ⇒ Object
Declare a one-to-many relationship.
-
#link_one(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) ⇒ Object
Declare a one-to-one relationship (FK on the child).
-
#link_ref(name, service:, foreign_key: nil, optional: false) ⇒ Object
Declare a reference relationship (FK on this record).
Instance Method Details
#association_registry ⇒ Object
Returns the AssociationRegistry for this class.
90 91 92 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 90 def association_registry @association_registry ||= AssociationRegistry.new end |
#inherited(subclass) ⇒ Object
94 95 96 97 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 94 def inherited(subclass) super subclass.instance_variable_set(:@association_registry, association_registry.dup) end |
#link_many(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) ⇒ Object
Declare a one-to-many relationship.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 36 def link_many(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) association_registry.register( AssociationDefinition.new( name, :has_many, service: service, foreign_key: foreign_key, dependent: dependent, validate: validate, async: async ) ) end |
#link_one(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) ⇒ Object
Declare a one-to-one relationship (FK on the child).
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 59 def link_one(name, service:, foreign_key: nil, dependent: :ignore, validate: true, async: false) association_registry.register( AssociationDefinition.new( name, :has_one, service: service, foreign_key: foreign_key, dependent: dependent, validate: validate, async: async ) ) end |
#link_ref(name, service:, foreign_key: nil, optional: false) ⇒ Object
Declare a reference relationship (FK on this record).
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/railsmith/base_service/association_dsl.rb', line 78 def link_ref(name, service:, foreign_key: nil, optional: false) association_registry.register( AssociationDefinition.new( name, :belongs_to, service: service, foreign_key: foreign_key, optional: optional ) ) end |