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
98 99 100 101 102 103 104 105 |
# File 'lib/rom/sql/plugin/associates.rb', line 98 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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rom/sql/plugin/associates.rb', line 57 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 |