Closed
Description
I've already posted this on Stackoverflow for more help, but I also post it here.
So I have models like this:
folder
,up_file
has 1chat_room
chat_room
belongs tocrmable
with polymorphic: true (so 1chat_room
may belongs tofolder
or 1up_file
)chat_room
has manycomments
comment
belongs tochat_room
anduser
(who posted the comment)
I've defined all relationship like this:
class Folder < ApplicationRecord
has_one :chat_room, as: :crmable, dependent: :destroy
end
class UpFile < ApplicationRecord
has_one :chat_room, as: :crmable, dependent: :destroy
end
class ChatRoom < ApplicationRecord
belongs_to :crmable, polymorphic: true
has_many :comments, dependent: :destroy
has_many :users, through: :comments
end
class Comment < ApplicationRecord
belongs_to :chat_room
belongs_to :user
end
I've follow their tutorial here but my associations not rendered.
class FolderSerializer < ActiveModel::Serializer
attributes :id, :name, :ancestry, :creator_name #... my other attributes
has_one :chat_room, include: [ :id, comments: :user ]
# ^ I tried to serialize folder's chat_room with all it comments, along with these comments' users.
end
All I got is this - chat_room
association not serialized?
Metadata
Assignees
Labels
No labels