This is my post model.
`import DS from 'ember-data';
const { Model } = DS;
export default Model.extend({
title: DS.attr('string'),
description: DS.attr('string'),
file: DS.attr(),
createdAt: DS.attr('date', {
defaultValue() { return new Date();}
}),
answers: DS.hasMany('answer')
});`
This is my answer model.
import DS from 'ember-data';
const { Model } = DS;
export default Model.extend({
answer: DS.attr('string'),
// image: DS.attr('string'),
createdAt: DS.attr('date', {
defaultValue() { return new Date();}
}),
post: DS.belongsTo('post'),
});
This is the template of the forum-details
`<h5>{{model.title}}</h5>
{{paper-divider}}
{{model.description}}
{{paper-divider}}
<strong>Comment:</strong><br>
{{model.answers}}
{{paper-divider}}`
The route for forum-details
`import Route from '@ember/routing/route';
export default Route.extend({
model: function() {
return this.modelFor('post').get('answers');
}
});`
This is the forum-details controller
actions: {
postAnswer(attrs){
let post = this.store.peekRecord('post', this.model.id);
console.log(post);
let answer = this.store.createRecord('answer', {
posts: post,
answer:attrs
});
answer.save();
},
}
Since the answer data is pass from the answer form component
`actions: {
postAnswer(ev){
ev.preventDefault(ev);
this.onsubmit({
answer: this.answer,
})
},
}`
But i still cant render the answer which belongs to the certain post. It only render DS.PromiseManyArray at the template when i call {{model.answers}}. Any solution suggest to fix it? Or correct me if i’m doing in a wrong way. And the forum-details is a nested route of a forum