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
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.
# File lib/sequel/model/associations.rb 1143 def assign_singular? 1144 super && (eager_limit_strategy != :ruby || !slice_range) 1145 end
Add conditions when filtering by singular associations with orders, since the underlying relationship is probably not one-to-one.
# File lib/sequel/model/associations.rb 1149 def filter_by_associations_add_conditions? 1150 super || self[:order] || self[:eager_limit_strategy] || self[:filter_limit_strategy] 1151 end
Make sure singular associations always have 1 as the limit
# File lib/sequel/model/associations.rb 1154 def limit_and_offset 1155 r = super 1156 if r.first == 1 1157 r 1158 else 1159 [1, r[1]] 1160 end 1161 end
Singular associations always return a single object, not an array.
# File lib/sequel/model/associations.rb 1164 def returns_array? 1165 false 1166 end
Private Instance Methods
Only use a eager limit strategy by default if there is an offset or an order.
# File lib/sequel/model/associations.rb 1171 def default_eager_limit_strategy 1172 super if self[:order] || offset 1173 end
Use a strategy for filtering by associations if there is an order or an offset, or a specific limiting strategy has been specified.
# File lib/sequel/model/associations.rb 1177 def filter_by_associations_limit_strategy 1178 super if self[:order] || offset || self[:eager_limit_strategy] || self[:filter_limit_strategy] 1179 end
Use the DISTINCT ON eager limit strategy for true if the database supports it.
# File lib/sequel/model/associations.rb 1182 def true_eager_graph_limit_strategy 1183 if associated_class.dataset.supports_ordered_distinct_on? && !offset 1184 :distinct_on 1185 else 1186 super 1187 end 1188 end