问题描述
我有两个模型作者和发布者(Rails),发行商有一个作者/作者属于发布者关系。
I have two models 'Author' and 'Publisher' (Rails), with a publisher hasOne author / author belongsTo publisher relationship.
我有Ember模型设置正确 - - 当我手动推入商店时,协会工作。但是,在请求/发布商索引时,只会创建发布商记录。
I have the Ember models setup correctly -- JS Fiddle -- and the associations working when I manually push into the store. But only the publisher records are created when requesting /publishers index.
我尝试过几种类型的JSON响应:
I've tried several types of JSON responses:
出版商作者
{ "publishers": [ { "id": 1, "name": "Test P 1", "author": 1 } ], "author": { "id": 1, "name": "Test A 1", "publisher": 1 } }
具有作者的发布商
{ "publishers": [ { "id": 1, "name": "Test P 1", "author": 1 } ], "authors": [{ "id": 1, "name": "Test A 1", "publisher": 1 }] }
作者嵌入的发布商
{ "publishers": [ { "id": 1, "name": "Test P 1", "author": { "id": 1 "name": "Test A 1" } } ] }
感谢任何帮助!
推荐答案
ActiveModelAdapter / ActiveModelSerializer expects _id / _ids p>
The ActiveModelAdapter/ActiveModelSerializer expects _id/_ids to be appended on relationships
{ "publishers": [ { "id": 1, "name": "Test P 1", "author_id": 1 } ], "authors": [{ "id": 1, "name": "Test A 1", "publisher_id": 1 }] }
这篇关于Ember Data belongsTo Association(JSON格式?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!