문제

In the case of relating 2 models, I'm not sure which model to add the reference to, or to add references to both.

Take the auto generated models for example:

The user model has a hasMany reference to accessToken, but the accessToken does not have a belongsTo reference to the user model.

Is it the case that the relation only goes on one side, and that side depends on if it's a 1 to 1 or a 1 to many? If not, please help me understand how to determine where to apply references in the loopback model architecture.

도움이 되었습니까?

해결책

You'll need to define relations per direction. As you pointed out, user.hasMany.accessTokens doesn't imply accessToken.belongsTo.user. Both need to be defined explicitly.

For more information, see http://strongloop.com/strongblog/defining-and-mapping-data-relations-with-loopback-connected-models.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top