0

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.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Coder1
  • 13,139
  • 15
  • 59
  • 89

1 Answers1

2

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.

Raymond Feng
  • 1,516
  • 9
  • 5