class Sequel::Plugins::PgArrayAssociations::PgArrayToManyAssociationReflection

  1. lib/sequel/plugins/pg_array_associations.rb
Superclass: Sequel::Model::Associations::AssociationReflection

The AssociationReflection subclass for pg_array_to_many associations.

Constants

FINALIZE_SETTINGS = superclass::FINALIZE_SETTINGS.merge( :array_type=>:array_type, :primary_key=>:primary_key, :primary_key_method=>:primary_key_method ).freeze  

Public Instance methods

array_type()
[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
189 def array_type
190   cached_fetch(:array_type) do
191     if (sch = self[:model].db_schema) && (s = sch[self[:key]]) && (t = s[:db_type])
192       t.sub(/\[\]\z/, '').freeze
193     else
194       :integer
195     end
196   end
197 end
associated_object_keys()

An array containing the primary key for the associated model.

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
200 def associated_object_keys
201   Array(primary_key)
202 end
can_have_associated_objects?(obj)

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

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
206 def can_have_associated_objects?(obj)
207   v = obj.get_column_value(self[:key])
208   v && !v.empty?
209 end
dataset_need_primary_key?()

pg_array_to_many associations do not need a primary key.

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
212 def dataset_need_primary_key?
213   false
214 end
default_key()

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

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
218 def default_key
219   :"#{singularize(self[:name])}_ids"
220 end
eager_graph_limit_strategy(_)

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

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
223 def eager_graph_limit_strategy(_)
224   :ruby if self[:limit]
225 end
eager_limit_strategy()

Always use the ruby eager limit strategy

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
228 def eager_limit_strategy
229   cached_fetch(:_eager_limit_strategy) do
230     :ruby if self[:limit]
231   end
232 end
filter_by_associations_conditions_expression(obj)
[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
269 def filter_by_associations_conditions_expression(obj)
270   ds = filter_by_associations_conditions_dataset.where(filter_by_associations_conditions_subquery_conditions(obj))
271   Sequel.function(:coalesce, Sequel.pg_array(filter_by_associations_conditions_key).overlaps(ds), Sequel::SQL::Constants::FALSE)
272 end
filter_by_associations_limit_strategy()

Don’t use a filter by associations limit strategy

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
235 def filter_by_associations_limit_strategy
236   nil
237 end
finalize_settings()
[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
244 def finalize_settings
245   FINALIZE_SETTINGS
246 end
handle_silent_modification_failure?()

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

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
250 def handle_silent_modification_failure?
251   self[:raise_on_save_failure] == false && self[:save_after_modify]
252 end
predicate_key()

A qualified version of the associated primary key.

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
255 def predicate_key
256   cached_fetch(:predicate_key){qualify_assoc(primary_key)}
257 end
primary_key()

The primary key of the associated model.

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
260 def primary_key
261   cached_fetch(:primary_key){associated_class.primary_key || raise(Error, "no primary key specified for #{associated_class.inspect}")}
262 end
primary_key_method()

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

[show source]
    # File lib/sequel/plugins/pg_array_associations.rb
265 def primary_key_method
266   cached_fetch(:primary_key_method){primary_key}
267 end