0
我有以下ActiveModel::Serializer
類加載ActiveModel遷移::串行從v0.9.2到0.8了,沒有的has_many被序列化
class MyThingySerializer < ActiveModel::Serializer
root false
attributes :id, :name, :description
has_many :whatsits, embed_namespace: :_embedded
delegate :whatsits, to: :object
end
據AMS 0.9.2下工作正常,但爲了添加一個可選屬性使用include_attributename?
機制有人告訴我,回滾到AMS 0.8
現在我whatsits
不會出現在我的_embedded
屬性下串行輸出。
有什麼特別的我需要做的,讓我的嵌入式whatsits
回來?
更新
我嘗試添加下面的方法到我的串行:
def whatsits
associated = self.class._associations[:whatsits]
associated.options[:root] = associated.options[:embed_namespace]
associated.options[:embed] = :objects
associated.options[:include] = true
object.whatsits
end
希望會得到串行器發出的_embedded
項下whatsits
名單,但很可惜的是沒't work ..
0.8的API是這裏https://github.com/rails-api/active_model_serializers/tree/8d31f7ee8c0ea3ed83ab871765f1444291278b41#embedding-associations沒有'embed_namespace'。可能'has_many:whatsits,root::_embedded' – robertjlooby 2015-03-19 13:10:02
唉,沒有把'embed_namespace'改爲'root'沒有幫助。我只需要手動去做就可以了。卷在AMS v0.10上 – 2015-03-19 21:57:07