Sails.js - 是否有用于支持"单向一对多"协会 [英] Sails.js - Is there intended support for a "one-way-many" association

查看:279
本文介绍了Sails.js - 是否有用于支持"单向一对多"协会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感兴趣的一个单向一对多关联。为了解释:

I'm interested in a one-way-many association. To explain:

// Dog.js
module.exports = {

    attributes: {
        name: {
            type: 'string'
        },
        favorateFoods: {
            collection: 'food',
            dominant: true
        }
    }
};

// Food.js
module.exports = {

    attributes: {
        name: {
            type: 'string'
        },
        cost: {
            type: 'integer'
        }
    }
};

在换句话说,我希望有一个来关联瓦特/ 食品条目,但作为食物,我不在乎它相关联。

In other words, I want a Dog to be associated w/ many Food entries, but as for Food, I don't care which Dog is associated.

如果我实际执行上述情况,信不信由你它的作品。但是,协会被命名为一个非常混乱的方式 - 甚至比正常更加混乱;)

If I actually implement the above, believe it or not it works. However, the table for the association is named in a very confusing manner - even more confusing than normal ;)

dog_favoritefoods__food_favoritefoods_food ID dog_favoritefoods ,和 food_favoritefoods_food

REST 蓝图模式功能只很好,我没有看到任何情况不妙,除了时髦的表名。

REST blueprints function with the Dog model just fine, I don't see anything that "looks bad" except for the funky table name.

所以,问题是,是否应该以这种方式工作,并没有任何人看到的东西,可能会潜在地就会失控?

So, the question is, is it supposed to work this way, and does anyone see something that might potentially go haywire?

推荐答案

我想你应该没问题。

但是,并没有真正似乎任何理由不完成的许多联想到很多。究其原因是由于已为单个集合创造了一切。连接表和它的属性已经存在。在这个等式中唯一缺少的是参考回到食物。

However, there does not really seem any reason to not complete the association for a Many to Many. The reason would be because everything is already being created for that single collection. The join table and its attributes are already there. The only thing missing in this equation is the reference back on food.

我能理解,如果把对食品协会是创建另一个表或创建另一个奇怪的加盟,但已经完成。真的是没有开销创建其它关联。

I could understand if putting the association on food were to create another table or create another weird join, but that has already been done. There really is no overhead to creating the other association.

所以理论上你不如创建它,从而避免任何潜在的冲突,除非你有一个非常令人信服的理由不?

So in theory you might as well create it, thus avoiding any potential conflicts unless you have a really compelling reason not to?

编辑:根据评论下面,我们应该注意到,人们可以基于电梯的图纸和创建的动态发现者开销体验

Edited: Based on the comments below we should note that one could experience overhead in lift based the blueprints and dynamic finders created.

这篇关于Sails.js - 是否有用于支持"单向一对多"协会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆