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
Source
# File lib/sequel/model/associations.rb 1304 def assign_singular? 1305 super && (eager_limit_strategy != :ruby || !slice_range) 1306 end
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.
Source
# File lib/sequel/model/associations.rb 1310 def filter_by_associations_add_conditions? 1311 super || self[:order] || self[:eager_limit_strategy] || self[:filter_limit_strategy] 1312 end
Add conditions when filtering by singular associations with orders, since the underlying relationship is probably not one-to-one.
Source
# File lib/sequel/model/associations.rb 1315 def limit_and_offset 1316 r = super 1317 if r.first == 1 1318 r 1319 else 1320 [1, r[1]] 1321 end 1322 end
Make sure singular associations always have 1 as the limit
Source
# File lib/sequel/model/associations.rb 1325 def returns_array? 1326 false 1327 end
Singular associations always return a single object, not an array.
Private Instance Methods
Source
# File lib/sequel/model/associations.rb 1332 def default_eager_limit_strategy 1333 super if self[:order] || offset 1334 end
Only use a eager limit strategy by default if there is an offset or an order.
Source
# File lib/sequel/model/associations.rb 1338 def filter_by_associations_limit_strategy 1339 super if self[:order] || offset || self[:eager_limit_strategy] || self[:filter_limit_strategy] 1340 end
Use a strategy for filtering by associations if there is an order or an offset, or a specific limiting strategy has been specified.
Source
# File lib/sequel/model/associations.rb 1343 def true_eager_graph_limit_strategy 1344 if associated_class.dataset.supports_ordered_distinct_on? && !offset 1345 :distinct_on 1346 else 1347 super 1348 end 1349 end
Use the DISTINCT ON eager limit strategy for true if the database supports it.