问题
I'm interested in a one-way-many
association. To explain:
// Dog.js
module.exports = {
attributes: {
name: {
type: 'string'
},
favorateFoods: {
collection: 'food',
dominant: true
}
}
};
and
// 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
, with id
, dog_favoritefoods
, and food_favoritefoods_food
.
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?
回答1:
I think you should be ok.
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.
来源:https://stackoverflow.com/questions/30198701/sails-js-is-there-intended-support-for-a-one-way-many-association