Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass _internalModel into a record when it is created #3262

Merged
merged 1 commit into from
Jun 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
});