Class: Sequel::Plugins::PgArrayAssociations::ManyToPgArrayAssociationReflection

Inherits:
Model::Associations::AssociationReflection show all
Defined in:
lib/sequel/plugins/pg_array_associations.rb

Overview

The AssociationReflection subclass for many_to_pg_array associations.

Constant Summary

Constants included from Inflections

Inflections::CAMELIZE_CONVERT_REGEXP, Inflections::CAMELIZE_MODULE_REGEXP, Inflections::DASH, Inflections::DEMODULIZE_CONVERT_REGEXP, Inflections::EMPTY_STRING, Inflections::SLASH, Inflections::UNDERSCORE, Inflections::UNDERSCORE_CONVERT_REGEXP1, Inflections::UNDERSCORE_CONVERT_REGEXP2, Inflections::UNDERSCORE_CONVERT_REPLACE, Inflections::UNDERSCORE_MODULE_REGEXP, Inflections::VALID_CONSTANT_NAME_REGEXP

Instance Method Summary collapse

Methods inherited from Model::Associations::AssociationReflection

#_add_method, #_remove_all_method, #_remove_method, #_setter_method, #add_method, #apply_dataset_changes, #associated_class, #associated_dataset, #association_method, #dataset_method, #dataset_need_primary_key?, #eager_graph_lazy_dataset?, #eager_limit_strategy, #eager_loader_key, #eager_loading_predicate_key, #eager_loading_use_associated_key?, #filter_by_associations_add_conditions?, #filter_by_associations_conditions_expression, #limit_and_offset, #need_associated_primary_key?, #predicate_keys, #qualify, #qualify_assoc, #qualify_cur, #reciprocal, #reciprocal_array?, #remove_all_method, #remove_method, #remove_should_check_existing?, #returns_array?, #select, #set_reciprocal_to_self?, #setter_method, #slice_range

Methods included from Inflections

clear, irregular, plural, singular, uncountable

Methods inherited from Hash

#&, #case, #hstore, #pg_json, #sql_expr, #sql_negate, #sql_or, #|, #~

Instance Method Details

#associated_object_keysObject

The array column in the associated model containing foreign keys to the current model.



80
81
82
# File 'lib/sequel/plugins/pg_array_associations.rb', line 80

def associated_object_keys
  [self[:key]]
end

#can_have_associated_objects?(obj) ⇒ Boolean

many_to_pg_array associations can have associated objects as long as they have a primary key.

Returns:

  • (Boolean)


86
87
88
# File 'lib/sequel/plugins/pg_array_associations.rb', line 86

def can_have_associated_objects?(obj)
  obj.send(self[:primary_key])
end

#default_keyObject

Assume that the key in the associated table uses a version of the current model’s name suffixed with _ids.



92
93
94
# File 'lib/sequel/plugins/pg_array_associations.rb', line 92

def default_key
  :"#{underscore(demodulize(self[:model].name))}_ids"
end

#predicate_keyObject

The hash key to use for the eager loading predicate (left side of IN (1, 2, 3))



97
98
99
# File 'lib/sequel/plugins/pg_array_associations.rb', line 97

def predicate_key
  cached_fetch(:predicate_key){qualify_assoc(self[:key_column])}
end

#primary_keyObject

The column in the current table that the keys in the array column in the associated table reference.



103
104
105
# File 'lib/sequel/plugins/pg_array_associations.rb', line 103

def primary_key
  self[:primary_key]
end

#remove_before_destroy?Boolean

Destroying the associated object automatically removes the association, since the association is stored in the associated object.

Returns:

  • (Boolean)


109
110
111
# File 'lib/sequel/plugins/pg_array_associations.rb', line 109

def remove_before_destroy?
  false
end