Created
October 16, 2017 15:06
-
-
Save samselikoff/6c3b6992cfaf9d0844cad13f0350dde9 to your computer and use it in GitHub Desktop.
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 './ext/reopen-ember-data-relationships'; |
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 DS from 'ember-data'; | |
/* | |
Force all associations to be async: false. | |
*/ | |
let originalBelongsTo = DS.belongsTo; | |
DS.belongsTo = function(...args) { | |
let options = args.find(arg => typeof arg === 'object'); | |
let newArgs = [...args]; | |
let newOptions = { async: false }; | |
if (options) { | |
Ember.assert(`We're monkey patching Ember Data to force sync relationships! You have a '${arguments[0]}' relationship defined somewhere with an 'async' option. Please remove it.`, options.async === undefined); | |
let optionsIndex = args.indexOf(options); | |
newOptions = Ember.assign({}, options, newOptions); | |
newArgs.splice(optionsIndex, 1, newOptions); | |
} else { | |
newArgs.push(newOptions); | |
} | |
return originalBelongsTo(...newArgs); | |
}; | |
let originalHasMany = DS.hasMany; | |
DS.hasMany = function(...args) { | |
let options = args.find(arg => typeof arg === 'object'); | |
let newArgs = [...args]; | |
let newOptions = { async: false }; | |
if (options) { | |
Ember.assert(`We're monkey patching Ember Data to force sync relationships! You have a '${arguments[0]}' relationship defined somewhere with an 'async' option. Please remove it.`, options.async === undefined); | |
let optionsIndex = args.indexOf(options); | |
newOptions = Ember.assign({}, options, newOptions); | |
newArgs.splice(optionsIndex, 1, newOptions); | |
} else { | |
newArgs.push(newOptions); | |
} | |
return originalHasMany(...newArgs); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment