ember.js - Ember Data embedded belongsTo relationship returning null -


i have 2 models:

question = ds.model.extend    answers: ds.hasmany("answer")  answer = ds.model.extend    question: ds.belongsto("question") 

the json serves answers embedded within questions:

"questions": [{   "id":"1.04"   "text":"what position or title of 1% being protested against?",   "answers":[     {       "text":"city mayor",       "id":"1.04.02"     },     {       "text":"city council member",       "id":"1.04.03"     },     {       "text":"ceo of company",       "id":"1.04.01"     }   ] }] 

when call question.get('answers'), ember returns expected array of answers. if, however, call answer.get('question'), null. idea why happening?

i think need tell ember relation embedded, done so.

question = ds.model.extend    answers: ds.hasmany("answer", embedded: 'always')  answer = ds.model.extend    question: ds.belongsto("question", embedded: 'always') 

with being said, might want rethink json structure, embedded records cause lot of dublicates.

ember expects following out of box.

{   "questions": [     {       "id": "1.04"       "text": "what position or title of 1% being protested against?"       "answer_ids": ["1.04.02", "1.04.03", "1.04.01"]     }   ],   "answers": [     {       "text": "city mayor",       "id": "1.04.02",       "question_id": "1.04"     },     {       "text": "city council member",       "id": "1.04.03",       "question_id": "1.04"     },     {       "text": "ceo of company",       "id": "1.04.01",       "question_id": "1.04"     }   ] } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -