Clarify caveats of parameterized association scope [ci-skip]
When joining or eager loading an association with a parameterized scope, the scope block will not be called with a `nil` argument. Rather, `ActiveRecord::Reflection::AssociationReflection#check_eager_loadable!` will raise an `ArgumentError`. Closes #43539. Co-authored-by: jcoleman <james.coleman@getbraintree.com>
This commit is contained in:
parent
ce23110829
commit
e0d384aeb4
@ -605,10 +605,11 @@ def association_instance_set(name, association)
|
||||
# has_many :birthday_events, ->(user) { where(starts_on: user.birthday) }, class_name: 'Event'
|
||||
# end
|
||||
#
|
||||
# Note: Joining and eager loading of these associations is not possible.
|
||||
# These two operations happen before instance creation and the scope will be called with a +nil+ argument.
|
||||
# It is allowed to be preloaded, but in the case that there's a different scope for each record,
|
||||
# this will perform N+1 queries. (this is essentially the same as preloading polymorphic scopes).
|
||||
# Note: Joining or eager loading such associations is not possible because
|
||||
# those operations happen before instance creation. Such associations
|
||||
# _can_ be preloaded, but doing so will perform N+1 queries because there
|
||||
# will be a different scope for each record (similar to preloading
|
||||
# polymorphic scopes).
|
||||
#
|
||||
# == Association callbacks
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user