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 1045 1045: def assign_singular? 1046: super && (eager_limit_strategy != :ruby || !slice_range) 1047: 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 1051 1051: def filter_by_associations_add_conditions? 1052: super || self[:order] || self[:eager_limit_strategy] || self[:filter_limit_strategy] 1053: end
Make sure singular associations always have 1 as the limit
# File lib/sequel/model/associations.rb, line 1056 1056: def limit_and_offset 1057: r = super 1058: if r.first == 1 1059: r 1060: else 1061: [1, r[1]] 1062: end 1063: end