【发布时间】:2013-03-17 00:21:02
【问题描述】:
我正在尝试将模型的关联序列化为关联模型的 ID (int) 数组。 我目前在 serializable_hash 中使用 :include 选项:
:include => {:associated => {:only => [:id]}
输出 json 像:
{"id":13, ...,"associated":[{"id":15,"associated":[]},{"id":14,"associated":[]}]}
不知道为什么关联的对象有一个“关联”键;但这不是很重要;我想要的是得到如下输出:
{"id":13, "associated":[15,14]}
我应该怎么做才能得到这个?
【问题讨论】:
标签: ruby-on-rails-3 activemodel active-model-serializers