Last active
July 26, 2018 23:17
-
-
Save Kilowhisky/5bee61b69a3813524b1d83b319c4fc30 to your computer and use it in GitHub Desktop.
HasMany Explosion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.RESTAdapter.extend({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
import { sort } from '@ember/object/computed'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
export default Model.extend({ | |
name: attr('string'), | |
positions: hasMany('position', { async: false }), | |
positionsSorted: sort('positions', 'positionsSortedBy'), | |
positionsSortedBy: ['utc:desc'] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
export default Model.extend({ | |
utc: attr('date'), | |
asset: belongsTo('asset', {async: true, inverse: 'positions'}), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import { hash } from 'rsvp'; | |
export default Ember.Route.extend({ | |
init(){ | |
this._super(...arguments); | |
}, | |
model(){ | |
// Push assets where no relationships are defined | |
this.store.pushPayload('asset',{ | |
assets: [{ id: 1, name: 'My Great Asset', positions: [] }] | |
}); | |
return hash({ | |
assets: this.store.peekAll('asset'), | |
positions: this.store.peekAll('position') | |
}); | |
}, | |
actions: { | |
loadPositions(){ | |
let date = Date.now(); | |
this.store.pushPayload('position',{ | |
positions: [{ id: date, utc: date, asset: 1 }] | |
}); | |
}, | |
cleanupPositions(){ | |
const positions = this.store.peekAll('position').sortBy('utc').reverse(); | |
let positionCount = positions.length; | |
while(positionCount > 1){ | |
let record = positions.popObject(); | |
this.store.unloadRecord(record); | |
positionCount--; | |
} | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.RESTSerializer.extend({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2", | |
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js" | |
}, | |
"addons": { | |
"ember-data": "3.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment