Whats wrong with this relationship in Ember.js? -
i error in basic ember application, couldn't figure out whats wrong.
uncaught error: assertion failed: looked 'author' relationship on 'question' id 101 of associated records not loaded. either create sure loaded parent record, or specify relationship async (ds.belongsto({ async: true }))
app.applicationstore = ds.store.extend({ adapter: ds.fixtureadapter }); app.question = ds.model.extend({ title: ds.attr('string'), question: ds.attr('string'), author: ds.belongsto('user') }); app.user = ds.model.extend({ fullname: ds.attr('string'), email: ds.attr('string'), questions: ds.hasmany('question', { async: true }) }); app.question.fixtures = [ { id: 101, title: 'how become expert?', author: 201, question: 'can become expert in ember?' }, { id: 102, title: 'are there lives in other planet?', author: 202, question: 'what chances of lives in other planets.' } ]; app.user.fixtures = [ { id: 201, fullname: 'ruby', email: 'ruby@rails', questions: [101] }, { id: 202, fullname: 'jruby', email: 'ruby@java', questions: [102] } ];
order of loading
<script src="js/app.js"></script> <script src="js/models/user_model.js"></script> <script src="js/models/question_model.js"></script> <script src="js/fixtures/question_fixtures.js"></script> <script src="js/fixtures/user_fixtures.js"></script>
your author needs async since it's supplied id, , not record.
app.question = ds.model.extend({ title: ds.attr('string'), question: ds.attr('string'), author: ds.belongsto('user', {async:true}) });
additionally store shouldn't defined anymore, define adapters/serializers
app.applicationadapter = ds.fixtureadapter;
ember.js ember-data
No comments:
Post a Comment