Skip to content

acts-as-taggable-on is incompatible with strict_loading_by_default #1176

Description

@crxssed7

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions