Module: ROM::SQL::Plugin::Associates::ClassMethods Private
- Defined in:
- lib/rom/sql/plugin/associates.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
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 = EMPTY_HASH) ⇒ Object
Instance Method Details
#associates(name, options = EMPTY_HASH) ⇒ Object
Set command to associate tuples with a parent tuple using provided keys
112 113 114 115 116 117 118 119 |
# File 'lib/rom/sql/plugin/associates.rb', line 112 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 = EMPTY_HASH) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rom/sql/plugin/associates.rb', line 70 def build(relation, = EMPTY_HASH) command = super configured_assocs = command.configured_associations = command.associations.map { |(name, opts)| next if configured_assocs.include?(name) AssociateOptions.new(name, relation, opts) }.compact .each { |opts| opts.ensure_valid(self) } before_hooks = .reject(&:after?).map(&:to_hash) after_hooks = .select(&:after?).map(&:to_hash) command. with_opts(configured_associations: configured_assocs + .map(&:name)). before(*before_hooks). after(*after_hooks) end |