module Sequel::Model::Associations::SingularAssociationReflection

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

Public Instance Methods

assign_singular?() click to toggle source

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.

Calls superclass method
# File lib/sequel/model/associations.rb, line 1044
def assign_singular?
  super && (eager_limit_strategy != :ruby || !slice_range)
end
filter_by_associations_add_conditions?() click to toggle source

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

Calls superclass method
# File lib/sequel/model/associations.rb, line 1050
def filter_by_associations_add_conditions?
  super || self[:order] || self[:eager_limit_strategy] || self[:filter_limit_strategy]
end
limit_and_offset() click to toggle source

Make sure singular associations always have 1 as the limit

Calls superclass method
# File lib/sequel/model/associations.rb, line 1055
def limit_and_offset
  r = super
  if r.first == 1
    r
  else
    [1, r[1]]
  end
end
returns_array?() click to toggle source

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

# File lib/sequel/model/associations.rb, line 1065
def returns_array?
  false
end

Private Instance Methods

default_eager_limit_strategy() click to toggle source

Only use a eager limit strategy by default if there is an offset or an order.

Calls superclass method
# File lib/sequel/model/associations.rb, line 1072
def default_eager_limit_strategy
  super if self[:order] || offset
end
filter_by_associations_limit_strategy() click to toggle source

Use a strategy for filtering by associations if there is an order or an offset, or a specific limiting strategy has been specified.

Calls superclass method
# File lib/sequel/model/associations.rb, line 1078
def filter_by_associations_limit_strategy
  super if self[:order] || offset || self[:eager_limit_strategy] || self[:filter_limit_strategy]
end
true_eager_graph_limit_strategy() click to toggle source

Use the DISTINCT ON eager limit strategy for true if the database supports it.

Calls superclass method
# File lib/sequel/model/associations.rb, line 1083
def true_eager_graph_limit_strategy
  if associated_class.dataset.supports_ordered_distinct_on? && !offset
    :distinct_on
  else
    super
  end
end