Class | Sequel::Plugins::PgArrayAssociations::PgArrayToManyAssociationReflection |
In: |
lib/sequel/plugins/pg_array_associations.rb
|
Parent: | Sequel::Model::Associations::AssociationReflection |
The AssociationReflection subclass for pg_array_to_many associations.
# File lib/sequel/plugins/pg_array_associations.rb, line 182 182: def array_type 183: cached_fetch(:array_type) do 184: if (sch = self[:model].db_schema) && (s = sch[self[:key]]) && (t = s[:db_type]) 185: t 186: else 187: :integer 188: end 189: end 190: end
An array containing the primary key for the associated model.
# File lib/sequel/plugins/pg_array_associations.rb, line 193 193: def associated_object_keys 194: Array(primary_key) 195: 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 199 199: def can_have_associated_objects?(obj) 200: v = obj.get_column_value(self[:key]) 201: v && !v.empty? 202: end
pg_array_to_many associations do not need a primary key.
# File lib/sequel/plugins/pg_array_associations.rb, line 205 205: def dataset_need_primary_key? 206: false 207: 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 211 211: def default_key 212: 213: "#{singularize(self[:name])}_ids" 214: end
Always use the ruby eager_graph limit strategy if association is limited.
# File lib/sequel/plugins/pg_array_associations.rb, line 216 216: def eager_graph_limit_strategy(_) 217: :ruby if self[:limit] 218: end
Always use the ruby eager limit strategy
# File lib/sequel/plugins/pg_array_associations.rb, line 221 221: def eager_limit_strategy 222: cached_fetch(:_eager_limit_strategy) do 223: :ruby if self[:limit] 224: end 225: end
# File lib/sequel/plugins/pg_array_associations.rb, line 253 253: def filter_by_associations_conditions_expression(obj) 254: ds = filter_by_associations_conditions_dataset.where(filter_by_associations_conditions_subquery_conditions(obj)) 255: Sequel.function(:coalesce, Sequel.pg_array(filter_by_associations_conditions_key).overlaps(ds), Sequel::SQL::Constants::FALSE) 256: end
Don‘t use a filter by associations limit strategy
# File lib/sequel/plugins/pg_array_associations.rb, line 228 228: def filter_by_associations_limit_strategy 229: nil 230: 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 234 234: def handle_silent_modification_failure? 235: self[:raise_on_save_failure] == false && self[:save_after_modify] 236: end
A qualified version of the associated primary key.
# File lib/sequel/plugins/pg_array_associations.rb, line 239 239: def predicate_key 240: cached_fetch(:predicate_key){qualify_assoc(primary_key)} 241: end
The primary key of the associated model.
# File lib/sequel/plugins/pg_array_associations.rb, line 244 244: def primary_key 245: cached_fetch(:primary_key){associated_class.primary_key || raise(Error, "no primary key specified for #{associated_class.inspect}")} 246: end