mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Merge pull request #601 from radanskoric/fix-nested-embed-in-root
Fix for nested embed_in_root when serializer used as part of an association
This commit is contained in:
23
test/fixtures/poro.rb
vendored
23
test/fixtures/poro.rb
vendored
@@ -22,9 +22,22 @@ class User < Model
|
||||
end
|
||||
end
|
||||
|
||||
class UserInfo < Model
|
||||
def user
|
||||
@user ||= User.new(name: 'N1', email: 'E1')
|
||||
end
|
||||
end
|
||||
|
||||
class Profile < Model
|
||||
end
|
||||
|
||||
class Category < Model
|
||||
def posts
|
||||
@posts ||= [Post.new(title: 'T1', body: 'B1'),
|
||||
Post.new(title: 'T2', body: 'B2')]
|
||||
end
|
||||
end
|
||||
|
||||
class Post < Model
|
||||
def comments
|
||||
@comments ||= [Comment.new(content: 'C1'),
|
||||
@@ -66,6 +79,10 @@ class UserSerializer < ActiveModel::Serializer
|
||||
has_one :profile
|
||||
end
|
||||
|
||||
class UserInfoSerializer < ActiveModel::Serializer
|
||||
has_one :user
|
||||
end
|
||||
|
||||
class ProfileSerializer < ActiveModel::Serializer
|
||||
def description
|
||||
description = object.read_attribute_for_serialization(:description)
|
||||
@@ -75,6 +92,12 @@ class ProfileSerializer < ActiveModel::Serializer
|
||||
attributes :name, :description
|
||||
end
|
||||
|
||||
class CategorySerializer < ActiveModel::Serializer
|
||||
attributes :name
|
||||
|
||||
has_many :posts
|
||||
end
|
||||
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
attributes :title, :body
|
||||
|
||||
|
||||
Reference in New Issue
Block a user