Open lukes opened 3 years ago
I ran into this same issue when fragment caching taggable records. I overrode the serializable_hash method on models using acts-as-taggable as a workaround.
private
def serializable_hash
self.attributes.reject{ |k, v| k == 'tag_list' }
end
Wondering if there is a better solution?
I'm having the same issue, it isn't a nice default i guess, it should be opt-in
I personally use serizlizer to do the handling with the following code. I would be happy if this information is useful to anyone!
class Model < ApplicationRecord
acts_as_taggable
end
class ModelSerializer < ApplicationSerializer
attributes :tag_list,
has_many :tags
# delegate :tag_list, to: :object
def tag_list
object.tags.pluck(:name)
end
end
Hi!
The use of
attribute
fortag_list
appears to be responsible for an N+1 SQL query problem when taggable records are serialized.Example:
This is due to the attribute's inclusion in
#serializable_hash
:Our workaround, because we do not need
tag_list
to be serialized is to alwaysexclude:
it:But this is a gotcha if we ever serialize a collection of records that are taggable, and forget to do this.