diff --git a/packages/ember-data/lib/system/debug/debug-adapter.js b/packages/ember-data/lib/system/debug/debug-adapter.js index fb81957483a..ee2ed753f23 100644 --- a/packages/ember-data/lib/system/debug/debug-adapter.js +++ b/packages/ember-data/lib/system/debug/debug-adapter.js @@ -5,6 +5,7 @@ import Model from "ember-data/system/model"; var get = Ember.get; var capitalize = Ember.String.capitalize; var underscore = Ember.String.underscore; +const { assert } = Ember; /** Extend `Ember.DataAdapter` with ED specific code. @@ -42,11 +43,18 @@ export default Ember.DataAdapter.extend({ return columns; }, - getRecords: function(modelNameOrFactory) { - // TODO: Ask Teddy what we should do here. - // Ideally this should always get passed a string. - - var modelName = typeof modelNameOrFactory === 'string' ? modelNameOrFactory : modelNameOrFactory.modelName; + getRecords: function(modelClass, modelName) { + if (arguments.length < 2) { + // Legacy Ember.js < 1.13 support + let containerKey = modelClass._debugContainerKey; + if (containerKey) { + let match = containerKey.match(/model:(.*)/); + if (match) { + modelName = match[1]; + } + } + } + assert("Cannot find model name. Please upgrade to Ember.js >= 1.13 for Ember Inspector support", !!modelName); return this.get('store').all(modelName); }, diff --git a/packages/ember-data/tests/integration/debug-adapter-test.js b/packages/ember-data/tests/integration/debug-adapter-test.js index 1bada903bd8..34f7356628f 100644 --- a/packages/ember-data/tests/integration/debug-adapter-test.js +++ b/packages/ember-data/tests/integration/debug-adapter-test.js @@ -15,8 +15,10 @@ module("DS.DebugAdapter", { App.Post = DS.Model.extend({ title: DS.attr('string') }); + + // TODO: Remove this when Ember is upgraded to >= 1.13 App.Post.reopenClass({ - modelName: 'post' + _debugContainerKey: 'model:post' }); }); @@ -26,7 +28,7 @@ module("DS.DebugAdapter", { debugAdapter.reopen({ getModelTypes: function() { - return Ember.A([{ klass: App.__container__.lookupFactory('model:post'), name: 'App.Post' }]); + return Ember.A([{ klass: App.__container__.lookupFactory('model:post'), name: 'post' }]); } }); }, @@ -40,7 +42,7 @@ test("Watching Model Types", function() { var added = function(types) { equal(types.length, 1); - equal(types[0].name, 'App.Post'); + equal(types[0].name, 'post'); equal(types[0].count, 0); strictEqual(types[0].object, store.modelFor('post')); }; @@ -74,7 +76,13 @@ test("Watching Records", function() { removedCount = count; }; - debugAdapter.watchRecords(App.__container__.lookupFactory('model:post'), recordsAdded, recordsUpdated, recordsRemoved); + let modelClassOrName; + if (debugAdapter.get('acceptsModelName')) { + modelClassOrName = 'post'; + } else { + modelClassOrName = App.__container__.lookupFactory('model:post'); + } + debugAdapter.watchRecords(modelClassOrName, recordsAdded, recordsUpdated, recordsRemoved); equal(get(addedRecords, 'length'), 1); record = addedRecords[0];