Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top