This adds support for PKs generated by the factory. A common example is using UUIDs as PKs.
ROM.container(:sql, conn) do |conf|
conf.default.create_table(:workers) do
column :id, :uuid, primary_key: true
column :name, String
end
conf.default.create_table(:jobs) do
column :id, :uuid, primary_key: true
foreign_key :worker_id, :workers, type: :uuid
column :name, String
end
conf.relation(:workers) do
schema(infer: true) do
associations do
has_many :jobs
end
end
end
conf.relation(:jobs) do
schema(infer: true) do
attribute :worker_id, ROM::SQL::Types.ForeignKey(:workers, ROM::SQL::Types::String)
associations do
belongs_to :worker
end
end
end
end
factories.define(:worker) do |f|
f.id { fake(:internet, :uuid) }
f.name "Test Worker"
f.association(:jobs, count: 0)
f.trait(:with_jobs) do |t|
t.association(:jobs, count: 2)
end
end
factories.define(:job) do |f|
f.id { fake(:internet, :uuid) }
f.name "Test Job"
f.association :worker
end
Bonus
This also improves returning persisted structs when RETURNING can't work as expected (ie in Sqlite or in case of PKs generated on the Ruby side).
This adds support for PKs generated by the factory. A common example is using UUIDs as PKs.
Bonus
This also improves returning persisted structs when
RETURNING
can't work as expected (ie in Sqlite or in case of PKs generated on the Ruby side).