diff --git a/addon/serializers/pouch.js b/addon/serializers/pouch.js index 6a892ae..6e25bab 100644 --- a/addon/serializers/pouch.js +++ b/addon/serializers/pouch.js @@ -1,3 +1,5 @@ import DS from 'ember-data'; -export default DS.RESTSerializer.extend({}); \ No newline at end of file +export default DS.RESTSerializer.extend({ + _shouldSerializeHasMany: function() { return true; } +}); \ No newline at end of file diff --git a/tests/dummy/app/models/food-item.js b/tests/dummy/app/models/food-item.js index 5a441cb..702c0d3 100644 --- a/tests/dummy/app/models/food-item.js +++ b/tests/dummy/app/models/food-item.js @@ -5,5 +5,6 @@ import DS from 'ember-data'; export default DS.Model.extend({ rev: DS.attr('string'), - name: DS.attr('string') + name: DS.attr('string'), + soup: DS.belongsTo('taco-soup', { async: true }) }); diff --git a/tests/dummy/app/serializers/application.js b/tests/dummy/app/serializers/application.js new file mode 100644 index 0000000..28d2f7a --- /dev/null +++ b/tests/dummy/app/serializers/application.js @@ -0,0 +1,3 @@ +import { Serializer } from 'ember-pouch/index'; + +export default Serializer; diff --git a/tests/integration/adapters/pouch-basics-test.js b/tests/integration/adapters/pouch-basics-test.js index 8b8ee92..b92973b 100644 --- a/tests/integration/adapters/pouch-basics-test.js +++ b/tests/integration/adapters/pouch-basics-test.js @@ -114,6 +114,36 @@ test('create a new record', function (assert) { }); }); +test('creating an associated record stores a reference to it in the parent', function (assert) { + assert.expect(1); + + var done = assert.async(); + Ember.RSVP.Promise.resolve().then(() => { + return this.db().bulkDocs([ + { _id: 'tacoSoup_2_C', data: { flavor: 'al pastor', ingredients: [] } } + ]); + }).then(() => { + return this.store().findRecord('taco-soup', 'C'); + }).then(tacoSoup => { + var newIngredient = this.store().createRecord('food-item', { + name: 'pineapple', + soup: tacoSoup + }); + + return newIngredient.save().then(() => tacoSoup.save()); + }).then(() => { + this.store().unloadAll(); + + return this.store().findRecord('taco-soup', 'C'); + }).then(tacoSoup => { + return tacoSoup.get('ingredients'); + }).then(foundIngredients => { + assert.deepEqual(foundIngredients.mapBy('name'), ['pineapple'], + 'should have fully loaded the associated items'); + done(); + }); +}); + // This test fails due to a bug in ember data // (https://github.com/emberjs/data/issues/3736) // starting with ED v2.0.0-beta.1. It works again with ED v2.1.0.