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