lib/sequel/plugins/pg_array_associations.rb in sequel-5.6.0 vs lib/sequel/plugins/pg_array_associations.rb in sequel-5.7.0
- old
+ new
@@ -78,11 +78,11 @@
Sequel.synchronize{Sequel::Model::Associations::ASSOCIATION_TYPES[:many_to_pg_array] = self}
def array_type
cached_fetch(:array_type) do
if (sch = associated_class.db_schema) && (s = sch[self[:key]]) && (t = s[:db_type])
- t
+ t.sub(/\[\]\z/, '').freeze
else
:integer
end
end
end
@@ -187,11 +187,11 @@
Sequel.synchronize{Sequel::Model::Associations::ASSOCIATION_TYPES[:pg_array_to_many] = self}
def array_type
cached_fetch(:array_type) do
if (sch = self[:model].db_schema) && (s = sch[self[:key]]) && (t = s[:db_type])
- t
+ t.sub(/\[\]\z/, '').freeze
else
:integer
end
end
end
@@ -398,10 +398,12 @@
o.save(save_opts)
end
end
opts[:clearer] ||= proc do
- opts.associated_dataset.where(Sequel.pg_array_op(key).contains([get_column_value(pk)])).update(key=>Sequel.function(:array_remove, key, get_column_value(pk)))
+ pk_value = get_column_value(pk)
+ db_type = opts.array_type
+ opts.associated_dataset.where(Sequel.pg_array_op(key).contains(Sequel.pg_array([pk_value], db_type))).update(key=>Sequel.function(:array_remove, key, Sequel.cast(pk_value, db_type)))
end
end
# Setup the pg_array_to_many-specific datasets, eager loaders, and modification methods.
def def_pg_array_to_many(opts)