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 collapse

FINALIZE_SETTINGS =
superclass::FINALIZE_SETTINGS.merge(
  :array_type=>:array_type
).freeze

Constants inherited from Model::Associations::AssociationReflection

Model::Associations::AssociationReflection::ASSOCIATION_DATASET_PROC

Instance Method Summary collapse

Methods inherited from Model::Associations::AssociationReflection

#_add_method, #_remove_all_method, #_remove_method, #_setter_method, #add_method, #apply_dataset_changes, #apply_distinct_on_eager_limit_strategy, #apply_eager_dataset_changes, #apply_eager_graph_limit_strategy, #apply_eager_limit_strategy, #apply_ruby_eager_limit_strategy, #apply_window_function_eager_limit_strategy, #assign_singular?, #associated_class, #associated_dataset, #association_dataset_for, #association_dataset_proc, #association_method, #cloneable?, #dataset_method, #dataset_need_primary_key?, #delete_row_number_column, #eager_graph_lazy_dataset?, #eager_load_results, #eager_loader_key, #eager_loading_use_associated_key?, #filter_by_associations_add_conditions?, #filter_by_associations_conditions_expression, #finalize, #initialize_association_cache, #inspect, #limit_and_offset, #need_associated_primary_key?, #placeholder_loader, #predicate_key_values, #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, #pg_jsonb, #sql_expr, #sql_negate, #sql_or, #|, #~

Instance Method Details

#array_typeObject


80
81
82
83
84
85
86
87
88
# File 'lib/sequel/plugins/pg_array_associations.rb', line 80

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

#associated_object_keysObject

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


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

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)

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

def can_have_associated_objects?(obj)
  obj.get_column_value(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.


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

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

#eager_graph_limit_strategy(_) ⇒ Object

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


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

def eager_graph_limit_strategy(_)
  :ruby if self[:limit]
end

#eager_limit_strategyObject

Always use the ruby eager limit strategy


114
115
116
117
118
# File 'lib/sequel/plugins/pg_array_associations.rb', line 114

def eager_limit_strategy
  cached_fetch(:_eager_limit_strategy) do
    :ruby if self[:limit]
  end
end

#filter_by_associations_limit_strategyObject

Don't use a filter by associations limit strategy


121
122
123
# File 'lib/sequel/plugins/pg_array_associations.rb', line 121

def filter_by_associations_limit_strategy
  nil
end

#finalize_settingsObject


128
129
130
# File 'lib/sequel/plugins/pg_array_associations.rb', line 128

def finalize_settings
  FINALIZE_SETTINGS
end

#handle_silent_modification_failure?Boolean

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

Returns:

  • (Boolean)

133
134
135
# File 'lib/sequel/plugins/pg_array_associations.rb', line 133

def handle_silent_modification_failure?
  self[:raise_on_save_failure] == false
end

#predicate_keyObject

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


138
139
140
# File 'lib/sequel/plugins/pg_array_associations.rb', line 138

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.


144
145
146
# File 'lib/sequel/plugins/pg_array_associations.rb', line 144

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)

150
151
152
# File 'lib/sequel/plugins/pg_array_associations.rb', line 150

def remove_before_destroy?
  false
end