I have a table with a column parent_id which is a foreign key to itself. Is it possible to combine the relation to itself for create command?
categories_relation.combine(:categories).command(:create).call(data)
My attempts to do this have failed.
Thanks!
UPDATE:
Given this relation…
class Categories < ROM::Relation[:sql]
schema(infer: true) do
associations do
has_many :categories
end
end
end
I am able to create records in the db…
category = {
name: 'cat 1',
categories: [{name: 'cat 1.1'}, {name: 'cat 1.2'}]
}
categories.combine(:categories).command(:create).call(category)
results in
[{:id=>1, :category_id=>nil, :name=>"cat 1"},
{:id=>2, :category_id=>nil, :name=>"cat 1.1"},
{:id=>3, :category_id=>nil, :name=>"cat 1.2"}]
However the parent association (category_id) is not getting assigned correctly. The desired result is:
[{:id=>1, :category_id=>nil, :name=>"cat 1"},
{:id=>2, :category_id=>1, :name=>"cat 1.1"},
{:id=>3, :category_id=>1, :name=>"cat 1.2"}]
This looks like a bug, could you report it in rom-rb/rom-sql?