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.

Methods

Public Instance methods

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 180
180:         def array_type
181:           cached_fetch(:array_type) do
182:             if (sch = self[:model].db_schema) && (s = sch[self[:key]]) && (t = s[:db_type])
183:               t
184:             else
185:               :integer
186:             end
187:           end
188:         end

An array containing the primary key for the associated model.

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 191
191:         def associated_object_keys
192:           Array(primary_key)
193:         end

pg_array_to_many associations can only have associated objects if the array field is not nil or empty.

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 197
197:         def can_have_associated_objects?(obj)
198:           v = obj.get_column_value(self[:key])
199:           v && !v.empty?
200:         end

pg_array_to_many associations do not need a primary key.

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 203
203:         def dataset_need_primary_key?
204:           false
205:         end

Use a default key name of *_ids, for similarity to other association types that use *_id for single keys.

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 209
209:         def default_key
210: 
211:           "#{singularize(self[:name])}_ids"
212:         end

Always use the ruby eager_graph limit strategy if association is limited.

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 214
214:         def eager_graph_limit_strategy(_)
215:           :ruby if self[:limit]
216:         end

Always use the ruby eager limit strategy

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 219
219:         def eager_limit_strategy
220:           cached_fetch(:_eager_limit_strategy) do
221:             :ruby if self[:limit]
222:           end
223:         end

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 251
251:         def filter_by_associations_conditions_expression(obj)
252:           ds = filter_by_associations_conditions_dataset.where(filter_by_associations_conditions_subquery_conditions(obj))
253:           Sequel.function(:coalesce, Sequel.pg_array(filter_by_associations_conditions_key).overlaps(ds), Sequel::SQL::Constants::FALSE)
254:         end

Don‘t use a filter by associations limit strategy

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 226
226:         def filter_by_associations_limit_strategy
227:           nil
228:         end

Handle silent failure of add/remove methods if raise_on_save_failure is false and save_after_modify is true.

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 232
232:         def handle_silent_modification_failure?
233:           self[:raise_on_save_failure] == false && self[:save_after_modify]
234:         end

A qualified version of the associated primary key.

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 237
237:         def predicate_key
238:           cached_fetch(:predicate_key){qualify_assoc(primary_key)}
239:         end

The primary key of the associated model.

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 242
242:         def primary_key
243:           cached_fetch(:primary_key){associated_class.primary_key || raise(Error, "no primary key specified for #{associated_class.inspect}")}
244:         end

The method to call to get value of the primary key of the associated model.

[Source]

     # File lib/sequel/plugins/pg_array_associations.rb, line 247
247:         def primary_key_method
248:           cached_fetch(:primary_key_method){primary_key}
249:         end

[Validate]