2015-06-22 55 views
3

Store.push(類型,數據)已被棄用。請提供一個JSON-API文檔對象作爲store.push的第一個也是唯一的參數自從升級到Ember 1.13.2和Ember數據後,Ember JS棄用錯誤1.13.3

我剛剛更新爲ember 1.13.2和ember-data 1.13.3,現在我收到大量的棄用消息在這篇文章的標題中提到。我不知道是什麼導致它出現,並且Ember Inspector的Deprecations選項卡不會顯示我的代碼中問題所在的位置。

如果有人能向我解釋信息的含義以及我需要做些什麼來解決它,我將不勝感激。

謝謝。

UPDATE:

我的自定義應用程序接口看起來是這樣的:

// app/adapters/application.js 
import ActiveModelAdapter from 'active-model-adapter'; 

export default ActiveModelAdapter.extend({ 
    host: 'http://dev.mydomain.com', 
    namespace: 'api/v1', 
}); 

它使用ActiveModelAdapter附加爲不同的過時消息解釋說,ActiveModelAdapter將不再與Ember數據捆綁自v2.0.0起。但是,我已經使用ember-data適配器和add來試用我的代碼,並且獲得了有關Store.push的同樣的棄用消息。

有一些堆棧跟蹤,因爲有相同棄用的多個版本,但這裏有一對夫婦:

DEPRECATION: store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push. 
    at ember$data$lib$system$store$$Service.extend.push (http://localhost:4200/assets/vendor.js:81014:17) 
    at http://localhost:4200/assets/vendor.js:83253:17 
    at Array.forEach (native) 
    at Ember.Mixin.create._extractEmbeddedHasMany (http://localhost:4200/assets/vendor.js:83251:68) 
    at null.<anonymous> (http://localhost:4200/assets/vendor.js:83219:22) 
    at http://localhost:4200/assets/vendor.js:84254:20 
    at cb (http://localhost:4200/assets/vendor.js:27380:11) 
    at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11) 
    at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18) 

DEPRECATION: store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push. 
    at ember$data$lib$system$store$$Service.extend.push (http://localhost:4200/assets/vendor.js:81014:17) 
    at Ember.Mixin.create._extractEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:83302:15) 
    at null.<anonymous> (http://localhost:4200/assets/vendor.js:83226:22) 
    at http://localhost:4200/assets/vendor.js:84254:20 
    at cb (http://localhost:4200/assets/vendor.js:27380:11) 
    at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11) 
    at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18) 
    at Function.ember$data$lib$system$model$$default.reopenClass.eachRelationship (http://localhost:4200/assets/vendor.js:84253:83) 
    at Ember.Mixin.create._extractEmbeddedRecords (http://localhost:4200/assets/vendor.js:83212:19) 

新的錯誤之後增加isNewSerailizerAPI:真實串行器(參見答案):

Error while processing route: elavonApplication.index Cannot read property 'id' of undefined TypeError: Cannot read property 'id' of undefined 
at ember$data$lib$serializers$embedded$records$mixin$$_newExtractEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:83482:33) 
at Ember.Mixin.create._extractEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:83349:98) 
at null.<anonymous> (http://localhost:4200/assets/vendor.js:83419:19) 
at http://localhost:4200/assets/vendor.js:84310:20 
at Map.forEach.cb (http://localhost:4200/assets/vendor.js:27380:11) 
at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11) 
at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18) 
at Function.ember$data$lib$system$model$$default.reopenClass.eachRelationship (http://localhost:4200/assets/vendor.js:84309:83) 
at ember$data$lib$serializers$embedded$records$mixin$$_newExtractEmbeddedRecords (http://localhost:4200/assets/vendor.js:83413:17) 
at Ember.Mixin.create._extractEmbeddedRecords (http://localhost:4200/assets/vendor.js:83265:96) 

從服務器返回的JSON確實包含「id」字段,但序列化程序似乎無法找到它,因爲我們收到錯誤並且模型未填充到Ember存儲區。

失敗行是:

// assets/vendor.js 
var belongsTo = { id: data.id, type: data.type }; 

,並把手錶上的「數據」變量,其中的「ID」正在尋找那就是「不確定」之後。 「數據」變量在代碼中定義:

var data = _normalizeEmbeddedRelationship2.data; 

所以我不知道這給近期考慮所有的餘燼,數據更改任何線索?

我也有可能涉及到的問題是一個棄用:

Ember Inspector (Deprecation Trace): Your custom serializer uses the old version of the Serializer API, with `extract` hooks. Please upgrade your serializers to the new Serializer API using `normalizeResponse` hooks instead. 
at ember$data$lib$system$store$serializer$response$$normalizeResponseHelper (http://localhost:4200/assets/vendor.js:74034:15) 
    at http://localhost:4200/assets/vendor.js:75772:25 
    at Object.Backburner.run (http://localhost:4200/assets/vendor.js:10776:25) 
    at ember$data$lib$system$store$$Service.extend._adapterRun (http://localhost:4200/assets/vendor.js:81352:33) 
    at http://localhost:4200/assets/vendor.js:75771:15 
    at tryCatch (http://localhost:4200/assets/vendor.js:65295:14) 
    at invokeCallback (http://localhost:4200/assets/vendor.js:65310:15) 
    at publish (http://localhost:4200/assets/vendor.js:65278:9) 
    at http://localhost:4200/assets/vendor.js:42094:7 

而且,重申現在我使用的是有源模型適配插件,而不是一個與Ember捆綁-data作爲建議的早期棄用消息。不知道這個附加組件在所有最近的更新之後是否與ember-data不兼容? (通過恢復到原始的捆綁適配器進行測試,仍然發生同樣的錯誤)。

+0

您是否有任何自定義適配器? –

+0

感謝您的快速響應!是的,我有一個自定義適配器,因爲我使用ActiveRecordAdapter。我已更新我的帖子以顯示適配器。 – danr1979

+0

您是否可以在開發人員控制檯中包含此棄用的堆棧跟蹤?這將有所幫助。 –

回答

6

如果你設置:

isNewSerializerAPI: true

在您的串行器應該解決的問題。

+0

即使使用'isNewSerializerAPI:true',我也會得到相同的消息。 –

+0

設置此屬性後,您能否提供錯誤的堆棧跟蹤?還是完全一樣?你也可以提供一個JSBin? – jmurphyau

+0

我現在正在得到一個不同的錯誤,即使我現在更新到了ember-data 1.13.4(昨天發佈),它仍然存在。我已將錯誤和其堆棧跟蹤添加到原始帖子的底部。 – danr1979

0

好的,這個問題似乎已經被最近的ember-data 1.13.4更新所修復。一旦我刪除我們嘗試使用較早的修復:

isNewSerializerAPI: true 

的串行(這引起其他問題),並更新到1.13.4一切正常,因爲它再次應該。

感謝您提供的幫助。

0

根據release docs push()現在將JSON API兼容有效內容視爲唯一參數。過去傳入推送的類型以JSON API格式存在,因此不再單獨需要。要「開箱即用」這項工作,您的API源必須返回有效的JSON API JSON數據。

如果這是不可能的,您需要一個自定義序列化程序來實現翻譯方法,以將API的JSON格式轉換爲JSON API格式。我認爲你可以在Serializer中的「normalizeResponse」中做到這一點。可以找到從舊串行器API到新的轉換的詳細信息here in the release docs