Any ways how we can merge two tables
Closed this issue · 1 comments
I am looking for a way how to merge two tables (join)
TableA:
id: 1, name_a: 'A row1',
id: 2, name_a: 'A row2'
id: 3, name_a: 'A row3'
TableB:
ref_id_a: 1, name_b: 'B row1',
ref_id_a: 2, name_b: 'B row2'
ref_id_a: 3, name_b: 'B row3'
I tried:
table "TableB", :embed_in => "TableA", :on => "ref_id_a"
I am expecting result as:
_id:123456789098765432100001, id: 1, name_a: 'A row1', name_b: 'B row1',
_id:123456789098765432100002, id: 2, name_a: 'A row2', name_b: 'B row2',
_id:123456789098765432100003, id: 3, name_a: 'A row3', name_b: 'B row3',
Hey @dgofman-equinix,
embed means that it will embed into the record as a child record (embedded). SO TableA row 1 would have an embedded table B row 1.
Is this always a one to one relationship? If so, you could use the before filter to pull the data to the parent, something like this:
table "preferences", :embed_in => "users" do
before_save do |pref_row, user_row, unset_user_row|
user_row.email_me = pref_row.delete('email_me')
end
end