Module: ROM::SQL::Plugin::Associates::ClassMethods
- Defined in:
- lib/rom/sql/plugin/associates.rb
Instance Method Summary collapse
-
#associates(name, options = EMPTY_HASH) ⇒ Object
Set command to associate tuples with a parent tuple using provided keys.
- #build(relation, **options) ⇒ Object
Instance Method Details
#associates(name, options = EMPTY_HASH) ⇒ Object
Set command to associate tuples with a parent tuple using provided keys
93 94 95 96 97 98 99 100 |
# File 'lib/rom/sql/plugin/associates.rb', line 93 def associates(name, = EMPTY_HASH) if associations.key?(name) raise ArgumentError, "#{name} association is already defined for #{self.class}" end associations(associations.merge(name => )) end |
#build(relation, **options) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rom/sql/plugin/associates.rb', line 53 def build(relation, **) command = super configured_assocs = command.configured_associations = command.associations.map { |(name, opts)| next if configured_assocs.include?(name) AssociateOptions.new(name, relation, opts) }.compact before_hooks = .reject(&:after?).map(&:to_hash) after_hooks = .select(&:after?).map(&:to_hash) command. with(configured_associations: configured_assocs + .map(&:name)). before(*before_hooks). after(*after_hooks) end |