开发者

Sproutcore - rails - Many-to-many - json

Consider two models in rails ModelA and ModelB, with their counterparts in Sproutcore. Suppose that we have a many-to-many relationship between the two models.

So, in ModelA, we have an attribute bArray, which contains references to ModelB objects. And in ModelB, we have an attribute aArray, which contains references to ModelA objects.

What I'd like to know is when you are writing the as_json() method to serve data from rails to sproutcore, would you include the bArray and aArray objects directly, or just take the bArray_ids and aArray_ids.

The reason I am asking the question is that including aArray and bArray copy ModelA and ModelB objects, inst开发者_如何学编程ead of just taking the id. What is the right way to do it?


I would use the ids. If for no other reason, a small transfer size. Sproutcore will model either structure, so I would just keep it simple.

When you load ModelA into the DataStore with ModelB references and vice versa, the DataStore will keep the most recent record with the corresponding id. So you would be wasting time nesting the records.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜