# File lib/sequel/plugins/pg_array_associations.rb, line 136 def primary_key self[:primary_key] end
class Sequel::Plugins::PgArrayAssociations::ManyToPgArrayAssociationReflection
The AssociationReflection subclass for many_to_pg_array associations.
Public Instance Methods
# File lib/sequel/plugins/pg_array_associations.rb, line 79 def array_type cached_fetch(:array_type) do if (sch = associated_class.db_schema) && (s = sch[self[:key]]) && (t = s[:db_type]) t else :integer end end end
The array column in the associated model containing foreign keys to the current model.
# File lib/sequel/plugins/pg_array_associations.rb, line 91 def associated_object_keys [self[:key]] end
many_to_pg_array associations can have associated objects as long as they have a primary key.
# File lib/sequel/plugins/pg_array_associations.rb, line 97 def can_have_associated_objects?(obj) obj.get_column_value(self[:primary_key]) end
Assume that the key in the associated table uses a version of the current model's name suffixed with _ids.
# File lib/sequel/plugins/pg_array_associations.rb, line 103 def default_key :"#{underscore(demodulize(self[:model].name))}_ids" end
Always use the ruby eager_graph limit strategy if association is limited.
# File lib/sequel/plugins/pg_array_associations.rb, line 108 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 113 def eager_limit_strategy cached_fetch(:_eager_limit_strategy) do :ruby if self[:limit] end end
Don't use a filter by associations limit strategy
# File lib/sequel/plugins/pg_array_associations.rb, line 120 def filter_by_associations_limit_strategy nil end
Handle silent failure of add/remove methods if raise_on_save_failure is false.
# File lib/sequel/plugins/pg_array_associations.rb, line 125 def handle_silent_modification_failure? self[:raise_on_save_failure] == false end
The hash key to use for the eager loading predicate (left side of IN (1, 2, 3))
# File lib/sequel/plugins/pg_array_associations.rb, line 130 def predicate_key cached_fetch(:predicate_key){qualify_assoc(self[:key_column])} end
The column in the current table that the keys in the array column in the associated table reference.
Destroying the associated object automatically removes the association, since the association is stored in the associated object.
# File lib/sequel/plugins/pg_array_associations.rb, line 142 def remove_before_destroy? false end
Private Instance Methods
The predicate condition to use for the eager_loader.
# File lib/sequel/plugins/pg_array_associations.rb, line 149 def eager_loading_predicate_condition(keys) Sequel.pg_array_op(predicate_key).overlaps(Sequel.pg_array(keys, array_type)) end
# File lib/sequel/plugins/pg_array_associations.rb, line 153 def filter_by_associations_add_conditions_dataset_filter(ds) key = qualify(associated_class.table_name, self[:key]) ds.select{unnest(key)}.exclude(key=>nil) end
# File lib/sequel/plugins/pg_array_associations.rb, line 158 def filter_by_associations_conditions_key qualify(self[:model].table_name, primary_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 164 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 168 def reciprocal_type :pg_array_to_many end
# File lib/sequel/plugins/pg_array_associations.rb, line 172 def use_placeholder_loader? false end