You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to include certain associations, clone others, and exclude any that aren't explicitly included or cloned. This doesn't seem to be supported, because apply_clones calls exclude_association (via exclude_clone_if_has_many_through), and exclude_association clears the includes array.
This isn't explicitly documented, and I had to discover it by stepping through in the debugger.
It looks from the code as though this is only meant to happen for has_many_through relations. However, even when association.options[:through] is nil, exclude_association(association.options[:through]) still gets called, and exclude_association clears the includes array even if its argument is nil.
It seems like it would be more correct for exclude_clone_if_has_many_through to do something like:
defexclude_clone_if_has_many_through(clone_field)association=@object_klass.reflect_on_association(clone_field)returnunlessassociation.macro == :has_many ||
association.is_a?(::ActiveRecord::Reflection::ThroughReflection)through_assoc=association.options[:through]returnunlessthrough_associfamoeba.includes.empty?# we're either in exclusive mode or we want to beamoeba.exclude_association(through_assoc)else# we're in inclusive modeamoeba.includes.delete(through_assoc)# no effect if already not includedend
but I don't know Amoeba well enough yet to know whether this would have other undesirable side effects.
The text was updated successfully, but these errors were encountered:
This has bitten me today, too, in a slightly different way:
If there are no calls to include_association or exclude_association, but calls to clone in the config, the model is forced into exclusive mode by the fact that clone clears the list (therefore includes is empty, triggering exclusive mode).
This means you can't only clone associations. As it is, I wonder if calling clone should trigger inclusive mode as well.
I want to include certain associations, clone others, and exclude any that aren't explicitly included or cloned. This doesn't seem to be supported, because
apply_clones
callsexclude_association
(viaexclude_clone_if_has_many_through
), andexclude_association
clears theincludes
array.This isn't explicitly documented, and I had to discover it by stepping through in the debugger.
It looks from the code as though this is only meant to happen for
has_many_through
relations. However, even whenassociation.options[:through]
is nil,exclude_association(association.options[:through])
still gets called, andexclude_association
clears theincludes
array even if its argument is nil.It seems like it would be more correct for
exclude_clone_if_has_many_through
to do something like:but I don't know Amoeba well enough yet to know whether this would have other undesirable side effects.
The text was updated successfully, but these errors were encountered: