When using Rails strict loading, saving a model using acts_as_taggable_on raises a StrictLoadingViolationError.
Reproduction
class Movie < ApplicationRecord
self.strict_loading_by_default = true
acts_as_taggable_on :tags
end
Controller:
@movie = Movie.new(movie_params)
if @movie.save
redirect_to edit_movie_path(@movie), notice: "Movie was successfully created."
else
render :new, status: :unprocessable_content
end
Calling @movie.save raises:
`Movie` is marked for strict_loading. The ActsAsTaggableOn::Tagging association named `:taggings` cannot be lazily loaded.
It appears the gem lazily loads the taggings association internally during save callbacks.
Notes
- This occurs even on newly created records.
- I've worked around this with the following, but its not an elegant solution and may break in the future:
has_many :taggings, as: :taggable, dependent: :destroy, class_name: "::ActsAsTaggableOn::Tagging", strict_loading: false
has_many :base_tags, through: :taggings, source: :tag, class_name: "::ActsAsTaggableOn::Tag", strict_loading: false
Expected behavior
acts-as-taggable-on should ideally support models using strict_loading_by_default without needing to disable strict loading on internal associations.
When using Rails strict loading, saving a model using
acts_as_taggable_onraises aStrictLoadingViolationError.Reproduction
Controller:
Calling
@movie.saveraises:It appears the gem lazily loads the taggings association internally during save callbacks.
Notes
Expected behavior
acts-as-taggable-onshould ideally support models usingstrict_loading_by_defaultwithout needing to disable strict loading on internal associations.