# File lib/sequel/plugins/pg_array_associations.rb, line 242 def primary_key cached_fetch(:primary_key){associated_class.primary_key || raise(Error, "no primary key specified for #{associated_class.inspect}")} end
class Sequel::Plugins::PgArrayAssociations::PgArrayToManyAssociationReflection
The AssociationReflection subclass for pg_array_to_many associations.
Public Instance Methods
# File lib/sequel/plugins/pg_array_associations.rb, line 180 def array_type cached_fetch(:array_type) do if (sch = self[:model].db_schema) && (s = sch[self[:key]]) && (t = s[:db_type]) t else :integer end end end
An array containing the primary key for the associated model.
# File lib/sequel/plugins/pg_array_associations.rb, line 191 def associated_object_keys Array(primary_key) end
pg_array_to_many associations can only have associated objects if the array field is not nil or empty.
# File lib/sequel/plugins/pg_array_associations.rb, line 197 def can_have_associated_objects?(obj) v = obj.get_column_value(self[:key]) v && !v.empty? end
pg_array_to_many associations do not need a primary key.
# File lib/sequel/plugins/pg_array_associations.rb, line 203 def dataset_need_primary_key? false end
Use a default key name of *_ids, for similarity to other association types that use *_id for single keys.
# File lib/sequel/plugins/pg_array_associations.rb, line 209 def default_key :"#{singularize(self[:name])}_ids" end
Always use the ruby eager_graph limit strategy if association is limited.
# File lib/sequel/plugins/pg_array_associations.rb, line 214 def eager_graph_limit_strategy(_) :ruby if self[:limit] end
Always use the ruby eager limit strategy
# File lib/sequel/plugins/pg_array_associations.rb, line 219 def eager_limit_strategy cached_fetch(:_eager_limit_strategy) do :ruby if self[:limit] end end
# File lib/sequel/plugins/pg_array_associations.rb, line 251 def filter_by_associations_conditions_expression(obj) ds = filter_by_associations_conditions_dataset.where(filter_by_associations_conditions_subquery_conditions(obj)) Sequel.function(:coalesce, Sequel.pg_array(filter_by_associations_conditions_key).overlaps(ds), Sequel::SQL::Constants::FALSE) end
Don't use a filter by associations limit strategy
# File lib/sequel/plugins/pg_array_associations.rb, line 226 def filter_by_associations_limit_strategy nil end
Handle silent failure of add/remove methods if raise_on_save_failure is false and save_after_modify is true.
# File lib/sequel/plugins/pg_array_associations.rb, line 232 def handle_silent_modification_failure? self[:raise_on_save_failure] == false && self[:save_after_modify] end
A qualified version of the associated primary key.
# File lib/sequel/plugins/pg_array_associations.rb, line 237 def predicate_key cached_fetch(:predicate_key){qualify_assoc(primary_key)} end
The primary key of the associated model.
The method to call to get value of the primary key of the associated model.
# File lib/sequel/plugins/pg_array_associations.rb, line 247 def primary_key_method cached_fetch(:primary_key_method){primary_key} end
Private Instance Methods
# File lib/sequel/plugins/pg_array_associations.rb, line 258 def filter_by_associations_add_conditions_dataset_filter(ds) pk = qualify(associated_class.table_name, primary_key) ds.select{array_agg(pk)}.exclude(pk=>nil) end
# File lib/sequel/plugins/pg_array_associations.rb, line 263 def filter_by_associations_conditions_key qualify(self[:model].table_name, self[:key]) end
Only consider an association as a reciprocal if it has matching keys and primary keys.
# File lib/sequel/plugins/pg_array_associations.rb, line 269 def reciprocal_association?(assoc_reflect) super && self[:key] == assoc_reflect[:key] && primary_key == assoc_reflect.primary_key end
# File lib/sequel/plugins/pg_array_associations.rb, line 273 def reciprocal_type :many_to_pg_array end
# File lib/sequel/plugins/pg_array_associations.rb, line 277 def use_placeholder_loader? false end