I'm testing out a very simple model relationship. I'm using the Fixture adapter before I switch to a true back-end. Somewhat following from here and here, I've found I need to define both sides of the relationship in each Fixture.
Is that a restriction of the Fixture adapter or will the backend/database also have to store both sides (which is non-standard for something like SQL)?
Models:
// app/models/comment.js
...
export default DS.Model.extend({
text: DS.attr('string'),
author: DS.attr('string'),
//post: DS.belongsTo('post', {async: true}) // async only needed on one side - true??
post: DS.belongsTo('post')
}).reopenClass({
FIXTURES: [
{
id: 1,
text: 'Text of the comment goes right in here',
author: 'Fred',
post: 1
},
{
id: 2,
text: 'TWO 2222 comment two here',
author: 'Barney',
post: 1
},
{
id: 3,
text: 'third comment here',
author: 'Wilma',
post: 2
},
...
// app/models/post.js
...
export default DS.Model.extend({
text: DS.attr('string'),
comments: DS.hasMany('comment', {async: true})
}).reopenClass({
FIXTURES: [
{
id: 1,
text: 'Post ONE - Lorem ipsum dolor sit amet, consectetur risus.',
comments: [1,2] // Why is this required??
},
{
id: 2,
text: 'Post TWO - consectetur adipiscing elit. Sed gravida faucibus risus.',
comments: [3,4] // Why is this required?
},
...
My ember info:
- Ember Inspector 1.8.2
- Ember 1.12.0
- Ember Data 1.0.0-beta.18
- jQuery 1.11.3