Module: Sequel::Model::Associations::SingularAssociationReflection

Overview

Methods that turn an association that returns multiple objects into an association that returns a single object.

Instance Method Summary collapse

Instance Method Details

#assign_singular?Boolean

Singular associations do not assign singular if they are using the ruby eager limit strategy and have a slice range, since they need to store the array of associated objects in order to pick the correct one with an offset.

Returns:

  • (Boolean)


1167
1168
1169
# File 'lib/sequel/model/associations.rb', line 1167

def assign_singular?
  super && (eager_limit_strategy != :ruby || !slice_range)
end

#filter_by_associations_add_conditions?Boolean

Add conditions when filtering by singular associations with orders, since the underlying relationship is probably not one-to-one.

Returns:

  • (Boolean)


1173
1174
1175
# File 'lib/sequel/model/associations.rb', line 1173

def filter_by_associations_add_conditions?
  super || self[:order] || self[:eager_limit_strategy] || self[:filter_limit_strategy]
end

#limit_and_offsetObject

Make sure singular associations always have 1 as the limit



1178
1179
1180
1181
1182
1183
1184
1185
# File 'lib/sequel/model/associations.rb', line 1178

def limit_and_offset
  r = super
  if r.first == 1
    r
  else
    [1, r[1]]
  end
end

#returns_array?Boolean

Singular associations always return a single object, not an array.

Returns:

  • (Boolean)


1188
1189
1190
# File 'lib/sequel/model/associations.rb', line 1188

def returns_array?
  false
end