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.

Methods

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.

[Source]

      # File lib/sequel/model/associations.rb, line 1125
1125:         def assign_singular?
1126:           super && (eager_limit_strategy != :ruby || !slice_range)
1127:         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, line 1131
1131:         def filter_by_associations_add_conditions?
1132:           super || self[:order] || self[:eager_limit_strategy] || self[:filter_limit_strategy]
1133:         end

Make sure singular associations always have 1 as the limit

[Source]

      # File lib/sequel/model/associations.rb, line 1136
1136:         def limit_and_offset
1137:           r = super
1138:           if r.first == 1
1139:             r
1140:           else
1141:             [1, r[1]]
1142:           end
1143:         end

Singular associations always return a single object, not an array.

[Source]

      # File lib/sequel/model/associations.rb, line 1146
1146:         def returns_array?
1147:           false
1148:         end

[Validate]