我有一个简单的活动模型序列化器:
class ActivitySerializer < ActiveModel::Serializer
attributes :id, :title, :description, :time
has_one :category
has_one :user
end
我也有类别和用户序列化程序,它们按预期工作。我得到这个有效载荷:
{"activities":[{"id":1,"title":"Test Activity","description":null,"time":"2014-03-01T06:05:41.027Z","category":{"id":1,"title":"Sports"},"user":{"id":1,"name":"ember"}}]}
但是,它们似乎没有加载到 ember 中。
App.Activity = DS.Model.extend
title: DS.attr('string')
description: DS.attr('string')
time: DS.attr('date')
category: DS.belongsTo('category')
user: DS.belongsTo('user')
App.Category = DS.Model.extend
title: DS.attr('string')
activities: DS.hasMany('activity')
App.User = DS.Model.extend
name: DS.attr('string')
activities: DS.hasMany('activity')
当我检查 ember 检查器时,未加载数据。ActiveModelSerializer 期望什么样的格式?它加载一个活动,但不加载类别或用户属性。