Open freibuis opened 1 year ago
I get a TypeError: can't quote Array
when just trying to run seeds on an existing table/model with composite primary keys
I have located were the issue is.
lib/seed-fu/seeder.rb
change in the def new
@constraints = constraints.to_a.empty? ? [:id] : constraints
to
@constraints = constraints.to_a.empty? ? [:id] : [constraints].flatten
the issue is in def update_id_sequence
@model_class.sequence_name.nil?
change
if @model_class.connection.adapter_name == "PostgreSQL" or @model_class.connection.adapter_name == "PostGIS"
return if @model_class.primary_key.nil? || @model_class.sequence_name.nil?
to
if @model_class.connection.adapter_name == "PostgreSQL" or @model_class.connection.adapter_name == "PostGIS"
return if @model_class.primary_key.is_a?(Array)
return if @model_class.primary_key.nil? || @model_class.sequence_name.nil?
then seed like this
id = 1
tennant_id =1
data = [{
id: [ tennant_id,id],
field1: 'foo',
field2: 'bar'
}]
Model.seed_once([:tennant_id,:id], *data)
# depending on how you built your primary composite key you might be able to still use
Model.seed_once( :id, *data)
hope this helps
As the title says... Rails now supports Composite keys,
would be nice to be able to supply an array of items as the key otherwise use :id using the terser-syntax
if this currently happens you will get the follow error