I have a serializer with some has_many
associations where I've modified the embed_key
.
I'm trying to have the IDs for my model be like path-name
rather than 12
. The code below is making that happen:
class SymbolSerializer < ActiveModel::Serializer
attributes :id,
:name,
:parent_id,
:rails_id
embed :ids, include: true
has_many :ancestors, embed_key: :symbol_path, serializer: SimplifiedSymbolSerializer
has_many :children, embed_key: :symbol_path, serializer: SimplifiedSymbolSerializer
has_one :parent, embed_key: :symbol_path, serializer: SimplifiedSymbolSerializer
has_many :siblings, embed_key: :symbol_path, serializer: SimplifiedSymbolSerializer
def id
object.symbol_path
end
def parent_id
object.id
end
def rails_id
object.id
end
end
The problem is that I'd like to still have the actual id
of the parent object (Which I've tried to do in my parent_id
method ^^).
Right now the overridden method still returns the :symbol_path
key rather than the id
.
Anyone know how to address this?