Check also associations for incomplete records
This commit is contained in:
parent
a8e85dc714
commit
6b40f127a1
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
get: (name) ->
|
get: (name) ->
|
||||||
if @constructor.isAttribute(name) && @get('incomplete') && !@isAttributeLoaded(name)
|
if @constructor.isAttribute(name) && @get('incomplete') && !@isAttributeLoaded(name)
|
||||||
|
console.log 'Loading rest of', @constructor, @get('clientId'), 'for key: ', name
|
||||||
@loadTheRest()
|
@loadTheRest()
|
||||||
|
|
||||||
@_super.apply this, arguments
|
@_super.apply this, arguments
|
||||||
|
@ -23,9 +24,14 @@
|
||||||
this
|
this
|
||||||
|
|
||||||
isAttributeLoaded: (name) ->
|
isAttributeLoaded: (name) ->
|
||||||
|
key = null
|
||||||
if meta = Ember.get(this.constructor, 'attributes').get(name)
|
if meta = Ember.get(this.constructor, 'attributes').get(name)
|
||||||
name = meta.key(this.constructor)
|
key = meta.key(this.constructor)
|
||||||
@get('store').isDataLoadedFor(this.constructor, @get('clientId'), name)
|
else if meta = Ember.get(this.constructor, 'associationsByName').get(name)
|
||||||
|
key = meta.options.key || @get('namingConvention').foreignKey(name)
|
||||||
|
|
||||||
|
if key
|
||||||
|
@get('store').isDataLoadedFor(this.constructor, @get('clientId'), key)
|
||||||
|
|
||||||
isComplete: (->
|
isComplete: (->
|
||||||
if @get 'incomplete'
|
if @get 'incomplete'
|
||||||
|
@ -82,4 +88,5 @@
|
||||||
Travis.app.store.adapter.pluralize(@singularName())
|
Travis.app.store.adapter.pluralize(@singularName())
|
||||||
|
|
||||||
isAttribute: (name) ->
|
isAttribute: (name) ->
|
||||||
Ember.get(this, 'attributes').has(name)
|
Ember.get(this, 'attributes').has(name) ||
|
||||||
|
Ember.get(this, 'associationsByName').has(name)
|
||||||
|
|
|
@ -3,6 +3,12 @@ Travis.Foo = Travis.Model.extend
|
||||||
description: DS.attr('string')
|
description: DS.attr('string')
|
||||||
lastName: DS.attr('string')
|
lastName: DS.attr('string')
|
||||||
|
|
||||||
|
bar: DS.belongsTo('Travis.Bar')
|
||||||
|
niceBar: DS.belongsTo('Travis.Bar')
|
||||||
|
veryNiceBar: DS.belongsTo('Travis.Bar', key: 'very_nice_bar_indeed_id')
|
||||||
|
|
||||||
|
Travis.Bar = Travis.Model.extend()
|
||||||
|
|
||||||
record = null
|
record = null
|
||||||
store = null
|
store = null
|
||||||
|
|
||||||
|
@ -18,6 +24,52 @@ describe 'Travis.Model', ->
|
||||||
afterEach ->
|
afterEach ->
|
||||||
store.destroy()
|
store.destroy()
|
||||||
|
|
||||||
|
describe 'with incomplete record with loaded associations', ->
|
||||||
|
beforeEach ->
|
||||||
|
attrs = {
|
||||||
|
id: 1
|
||||||
|
bar_id: 2
|
||||||
|
nice_bar_id: 3
|
||||||
|
very_nice_bar_indeed_id: 4
|
||||||
|
}
|
||||||
|
record = store.loadIncomplete(Travis.Foo, attrs)
|
||||||
|
store.load(Travis.Bar, id: 2)
|
||||||
|
store.load(Travis.Bar, id: 3)
|
||||||
|
store.load(Travis.Bar, id: 4)
|
||||||
|
|
||||||
|
it 'does not load record on association access', ->
|
||||||
|
expect( record.get('bar.id') ).toEqual 2
|
||||||
|
expect( record.get('niceBar.id') ).toEqual 3
|
||||||
|
expect( record.get('veryNiceBar.id') ).toEqual 4
|
||||||
|
waits 50
|
||||||
|
runs ->
|
||||||
|
expect( record.get('complete') ).toBeFalsy()
|
||||||
|
|
||||||
|
describe 'with incomplete record without loaded associations', ->
|
||||||
|
beforeEach ->
|
||||||
|
attrs = {
|
||||||
|
id: 1
|
||||||
|
}
|
||||||
|
record = store.loadIncomplete(Travis.Foo, attrs)
|
||||||
|
|
||||||
|
it 'loads record based on regular association key', ->
|
||||||
|
record.get('bar')
|
||||||
|
waits 50
|
||||||
|
runs ->
|
||||||
|
expect( record.get('complete') ).toBeTruthy()
|
||||||
|
|
||||||
|
it 'loads record based on camel case association key', ->
|
||||||
|
record.get('niceBar')
|
||||||
|
waits 50
|
||||||
|
runs ->
|
||||||
|
expect( record.get('complete') ).toBeTruthy()
|
||||||
|
|
||||||
|
it 'loads record based on ssociation with explicit key', ->
|
||||||
|
record.get('veryNiceBar')
|
||||||
|
waits 50
|
||||||
|
runs ->
|
||||||
|
expect( record.get('complete') ).toBeTruthy()
|
||||||
|
|
||||||
describe 'with incomplete record', ->
|
describe 'with incomplete record', ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
attrs = {
|
attrs = {
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -9011,9 +9011,16 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
|
||||||
Travis.Foo = Travis.Model.extend({
|
Travis.Foo = Travis.Model.extend({
|
||||||
name: DS.attr('string'),
|
name: DS.attr('string'),
|
||||||
description: DS.attr('string'),
|
description: DS.attr('string'),
|
||||||
lastName: DS.attr('string')
|
lastName: DS.attr('string'),
|
||||||
|
bar: DS.belongsTo('Travis.Bar'),
|
||||||
|
niceBar: DS.belongsTo('Travis.Bar'),
|
||||||
|
veryNiceBar: DS.belongsTo('Travis.Bar', {
|
||||||
|
key: 'very_nice_bar_indeed_id'
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Travis.Bar = Travis.Model.extend();
|
||||||
|
|
||||||
record = null;
|
record = null;
|
||||||
|
|
||||||
store = null;
|
store = null;
|
||||||
|
@ -9037,6 +9044,66 @@ return sinon;}.call(typeof window != 'undefined' && window || {}));
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
return store.destroy();
|
return store.destroy();
|
||||||
});
|
});
|
||||||
|
describe('with incomplete record with loaded associations', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
var attrs;
|
||||||
|
attrs = {
|
||||||
|
id: 1,
|
||||||
|
bar_id: 2,
|
||||||
|
nice_bar_id: 3,
|
||||||
|
very_nice_bar_indeed_id: 4
|
||||||
|
};
|
||||||
|
record = store.loadIncomplete(Travis.Foo, attrs);
|
||||||
|
store.load(Travis.Bar, {
|
||||||
|
id: 2
|
||||||
|
});
|
||||||
|
store.load(Travis.Bar, {
|
||||||
|
id: 3
|
||||||
|
});
|
||||||
|
return store.load(Travis.Bar, {
|
||||||
|
id: 4
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return it('does not load record on association access', function() {
|
||||||
|
expect(record.get('bar.id')).toEqual(2);
|
||||||
|
expect(record.get('niceBar.id')).toEqual(3);
|
||||||
|
expect(record.get('veryNiceBar.id')).toEqual(4);
|
||||||
|
waits(50);
|
||||||
|
return runs(function() {
|
||||||
|
return expect(record.get('complete')).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('with incomplete record without loaded associations', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
var attrs;
|
||||||
|
attrs = {
|
||||||
|
id: 1
|
||||||
|
};
|
||||||
|
return record = store.loadIncomplete(Travis.Foo, attrs);
|
||||||
|
});
|
||||||
|
it('loads record based on regular association key', function() {
|
||||||
|
record.get('bar');
|
||||||
|
waits(50);
|
||||||
|
return runs(function() {
|
||||||
|
return expect(record.get('complete')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('loads record based on camel case association key', function() {
|
||||||
|
record.get('niceBar');
|
||||||
|
waits(50);
|
||||||
|
return runs(function() {
|
||||||
|
return expect(record.get('complete')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return it('loads record based on ssociation with explicit key', function() {
|
||||||
|
record.get('veryNiceBar');
|
||||||
|
waits(50);
|
||||||
|
return runs(function() {
|
||||||
|
return expect(record.get('complete')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('with incomplete record', function() {
|
describe('with incomplete record', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
var attrs;
|
var attrs;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
bce1e34d
|
6eb17b9d
|
Loading…
Reference in New Issue
Block a user