この質問は AMS 0.8 に関するものです
私は2つのモデルを持っています:
class Subject < ActiveRecord::Base
has_many :user_combinations
has_ancestry
end
class UserCombination < ActiveRecord::Base
belongs_to :stage
belongs_to :subject
belongs_to :user
end
および 2 つのシリアライザー:
class UserCombinationSerializer < ActiveModel::Serializer
attributes :id
belongs_to :stage
belongs_to :subject
end
class SubjectSerializer < ActiveModel::Serializer
attributes :id, :name, :description, :subjects
def include_subjects?
object.is_root?
end
def subjects
object.subtree
end
end
aUserCombination
がシリアライズされたら、サブジェクトのサブツリー全体を埋め込みたいと思います。
このセットアップを使用しようとすると、次のエラーが発生します。
undefined method `belongs_to' for UserCombinationSerializer:Class
をこれに変更してみUserCombinationSerializer
ました:
class UserCombinationSerializer < ActiveModel::Serializer
attributes :id, :subject, :stage
end
この場合、エラーは発生しませんが、 がsubject
間違った方法でシリアル化されていSubjectSerializer
ます。
私の質問:
- シリアライザーで belongs_to リレーションを使用できるようにすべきではありませんか?
- そうでない場合-どうすれば望ましい動作を得ることができますか-SubjectSerializerを使用してサブジェクトツリーを埋め込みますか?