-
-
Save runspired/13004a0eae8fddb543e7705d372eb1b0 to your computer and use it in GitHub Desktop.
ember-data belongsTo proxy unresolved REPL
This file contains hidden or 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 EmberObject from '@ember/object'; | |
import { resolve } from 'rsvp'; | |
export default class ApplicationAdapter extends EmberObject { | |
findRecord() { | |
return resolve({ | |
data: { | |
type: 'parent', | |
id: '1', | |
attributes: { | |
name: 'John' | |
}, | |
relationships: { | |
children: { | |
data: [ | |
{ type: 'child', id: '1' }, | |
{ type: 'child', id: '2' } | |
] | |
} | |
} | |
}, | |
included: [ | |
{ | |
type: 'child', | |
id: '1', | |
attributes: { | |
name: 'Chris' | |
}, | |
}, | |
{ | |
type: 'child', | |
id: '2', | |
attributes: { | |
name: 'Jim' | |
}, | |
} | |
] | |
}); | |
} | |
} |
This file contains hidden or 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({ | |
name: attr(), | |
parent: belongsTo('parent', { | |
async: false, | |
inverse: 'children' | |
}) | |
}); |
This file contains hidden or 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({ | |
name: attr(), | |
children: hasMany('child', { | |
// it does not matter whether this is true or false | |
async: false, | |
inverse: 'parent' | |
}) | |
}); |
This file contains hidden or 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 Route from '@ember/routing/route'; | |
export default Route.extend({ | |
model() { | |
return this.get('store').findRecord('parent', '1'); | |
}, | |
actions: { | |
checkInJs(child) { | |
console.log({ | |
child, | |
dotParent: child.parent, | |
getParent: child.get('parent') | |
}); | |
} | |
} | |
}); |
This file contains hidden or 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
export default class ApplicationSerializer { | |
constructor(config) { | |
Object.assign(this, config); | |
} | |
static create(config) { | |
return new this(config); | |
} | |
normalizeResponse(_, __, data) { return data; } | |
} |
This file contains hidden or 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.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"ENV": {}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.7.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment