class Tag < ActiveRecord::Base
belongs_to :note
end
class TagSerializer < ActiveModel::Serializer
attributes :id
embed :ids, include: true
has_one :note
end
class Note < ActiveRecord::Base
has_many :tags
end
class NoteSerializer < ActiveModel::Serializer
attributes :id, :content, :name
has_many :tags
embed :ids, include: true
end
If we serialize tag it produces:
WITH notes_ids AS
(
SELECT "notes"."id"
FROM "notes"
WHERE "notes"."note_id" IN ( SELECT "tags_ids"."id" FROM "tags_ids")
)
...
Where tag_ids is defined afterwards so is not found in this query and note_id does not belong in notes table.
If we serialize tag it produces:
Where
tag_ids
is defined afterwards so is not found in this query andnote_id
does not belong innotes
table.