Module | Sequel::Model::Associations::SingularAssociationReflection |
In: |
lib/sequel/model/associations.rb
|
Methods that turn an association that returns multiple objects into an association that returns a single object.
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, line 1126 1126: def assign_singular? 1127: super && (eager_limit_strategy != :ruby || !slice_range) 1128: 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, line 1132 1132: def filter_by_associations_add_conditions? 1133: super || self[:order] || self[:eager_limit_strategy] || self[:filter_limit_strategy] 1134: end
Make sure singular associations always have 1 as the limit
# File lib/sequel/model/associations.rb, line 1137 1137: def limit_and_offset 1138: r = super 1139: if r.first == 1 1140: r 1141: else 1142: [1, r[1]] 1143: end 1144: end