Class: ROM::Changeset::Associated
- Inherits:
-
Object
- Object
- ROM::Changeset::Associated
- Defined in:
- changeset/lib/rom/changeset/associated.rb
Overview
Associated changesets automatically set up FKs
Instance Attribute Summary collapse
-
#associations ⇒ Array
readonly
List of association identifiers from relation schema.
-
#left ⇒ Changeset::Create
readonly
Child changeset.
Instance Method Summary collapse
-
#associate(other, name = Associated.infer_assoc_name(other)) ⇒ Associated
Associate with other changesets.
-
#command ⇒ ROM::Command::Composite
Create a composed command.
-
#commit ⇒ Array<Hash>, Hash
Commit changeset's composite command.
Instance Attribute Details
#associations ⇒ Array (readonly)
Returns List of association identifiers from relation schema.
19 |
# File 'changeset/lib/rom/changeset/associated.rb', line 19 option :associations |
#left ⇒ Changeset::Create (readonly)
Returns Child changeset.
15 |
# File 'changeset/lib/rom/changeset/associated.rb', line 15 param :left |
Instance Method Details
#associate(other, name = Associated.infer_assoc_name(other)) ⇒ Associated
Associate with other changesets
65 66 67 |
# File 'changeset/lib/rom/changeset/associated.rb', line 65 def associate(other, name = Associated.infer_assoc_name(other)) self.class.new(left, associations: associations.merge(name => other)) end |
#command ⇒ ROM::Command::Composite
Create a composed command
This works only with parent => child(ren) changeset hierarchy
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'changeset/lib/rom/changeset/associated.rb', line 89 def command associations.reduce(left.command.curry(left)) do |a, (assoc, other)| case other when Changeset a >> other.command.with_association(assoc).curry(other) when Associated a >> other.command.with_association(assoc) when Array raise NotImplementedError, 'Changeset::Associate does not support arrays yet' else a.with_association(assoc, parent: other) end end end |
#commit ⇒ Array<Hash>, Hash
Commit changeset's composite command
54 55 56 |
# File 'changeset/lib/rom/changeset/associated.rb', line 54 def commit command.call end |