2013-11-22 57 views
2

我使用的是ember-data v1.0.0-beta.3,活動模型串行器和DS.ActiveModelAdapter。我有一個模型,它看起來是這樣的:可空屬性在ember-data中的關係?

App.Listing = DS.Model.extend 
title: DS.attr() 
pickupAddress: DS.belongsTo("address") 

App.Address = DS.Model.extend 
    listing: DS.belongsTo("listing") 
    address: DS.attr() 

我想pickupAddress領域是可選的,和我的/目錄/ {ID} JSON看起來是這樣的:

{ 
    "pickup_addresses":[], 
    "listing":{"id":2,"title":"Foobar", "pickup_address_id":null} 
} 

然而,餘燼-data不喜歡這樣,它給了我這個錯誤:

Assertion failed: No model was found for 'pickupAddress'

它支持這種情況嗎?有一些選項可以傳遞給belongsTo嗎?或者我應該創建一些自定義適配器?

感謝

回答

3

問題是與你的有效載荷,已傳輸的數據需要匹配一個類名,你的樣品中你有pickup_addresses,正確的是addresses

{ 
    "addresses": [], 
    "listing": { 
     "id": 2, 
     "title": "Foobar", 
     "pickup_address_id": null 
    } 
} 
+0

大。完美的工作,謝謝。 – Charlie