Posts have many tags and Tags have many posts. In Rails, I'll typically need to make a Post_Tags model and migration to join the two models.
Using an EmberJS front-end, I'm not sure how to do the serializers and if a Post_Tags model is necessary.
The models in Ember:
// app/models/post.js
export default DS.Model.extend({
heading: DS.attr('string'),
content: DS.attr(''),
fullImageUrl: DS.string('author'),
thumbnailUrl: DS.attr('string'),
pageId: DS.belongsTo('page'),
tagIds: DS.hasMany('tag')
});
// app/models/tag.js
export default DS.Model.extend({
name: DS.attr('string'),
postIds: DS.hasMany('post')
});
The expected JSON with an ActiveModelAdapter should be:
"posts": [{
"id": 1,
"heading": "foo",
"content": ,
"full_image_url": "foo",
"thumbnail_url": "foo",
"page_id": <page id>,
"tag_ids": [<tag ids>] }],
"tags": [{
"id": 1,
"name": "foo",
"post_ids": [<post ids>]
}]
Do I still need a Post_Tags model that belongs_to :post and belongs_to :tag? Do I need a Post_Tags serializer? Or will just saying has_many :posts in the Tag serializer and vice versa be enough?