Skip to content

Commit

Permalink
Merge pull request #3262 from bmac/create-internal-model
Browse files Browse the repository at this point in the history
Pass _internalModel into a record when it is created
  • Loading branch information
igorT committed Jun 8, 2015
2 parents 8d7bcc0 + 7bd5993 commit 5b4e514
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/ember-data/lib/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ InternalModel.prototype = {
this.record = this.type._create({
id: this.id,
store: this.store,
container: this.container
container: this.container,
_internalModel: this
});
this.record._internalModel = this;
this._triggerDeferredTriggers();
},

Expand Down
1 change: 1 addition & 0 deletions packages/ember-data/lib/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var retrieveFromCurrentState = Ember.computed('currentState', function(key) {
var Model = Ember.Object.extend(Ember.Evented, {
_recordArrays: undefined,
_relationships: undefined,
_internalModel: null,

store: null,

Expand Down
20 changes: 20 additions & 0 deletions packages/ember-data/tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,3 +869,23 @@ test('toJSON looks up the JSONSerializer using the store instead of using JSONSe
ok(!errorThrown, 'error not thrown due to missing store');
deepEqual(json, {});
});


test('accessing attributes in the initializer should not throw an error', function() {
expect(1);
var Person = DS.Model.extend({
name: DS.attr('string'),

init: function() {
this._super.apply(this, arguments);
ok(!this.get('name'));
}
});

var env = setupStore({
person: Person
});
var store = env.store;

run(_ => store.createRecord('person'));
});

0 comments on commit 5b4e514

Please sign in to comment.