In this example, I'd suggest embedding the tags in the Post, so that the resulting structure looks like this
{
title: "some post",
tags: [ "tag1", "tag2" ]
}
This is generally good practice when you don't need to have additional value on the relation. If you want to have the Tag
model on the client, you can still do it via embedding.
{
title: "some post",
tags: [ { name: "first tag" }, { name: "second tag" } ]
}
in this case you could specify it as an embedded relation, such as this
App.Post = DS.Model.extend({
title: DS.attr("string"),
tags: DS.hasMany("App.Tag")
});
App.Tag = DS.Model.extend({
name: DS.attr("string"),
post: DS.belongsTo("App.Post")
});
App.store.adapter.serializer.map("App.Tag", {
tags: { embedded: 'load' }
});
keep in mind that embedding only works in Ember Data revision 10. It is not supported in 5-9.
Most of the time you don't really want to model everything the same way as you would model it in a relation database.
You should lean towards NoSQL-ish JSON, which generally means embedding things, rather than making complex associations. The reason for this is that your database can JOIN
data very efficiently, especially with indexes, but doing this over the network is a bad idea because it results in a lot of requests.