0

I am trying to create a loopback model which stores the details of a user, the model is supposed to store the details of the user like his address, email and phone number and so on.

My doubt is whether I create a separate model which stores these details separately or do i store the fields along with the user credentials into a single model ?

UPDATE: After going through and experimenting on my project I have to conclude that storing userdetails on the same model is not a good idea as Loopback would validate the users credentials and takes in the user details as part of the post request and if the properties there are set to required, then it automatically fails.

Bazinga777
  • 5,140
  • 13
  • 53
  • 92
  • If you're asking about the pros/cons of keeping two separate models for personal info vs login info then I'd say that keep it all in the same model and use ACLs to manage access the way you want in one place as I foresee no merits to splitting them up. Also if you are simply asking in a matter of fact way: "Is it common practice to keep user info with creds info ... or not in loopback?" Then again yes its ok to keep personal info of the user with the class that has the creds info. There isn't any separation prescribed by the loopback framework. Other than that @superkhau's answer applies – pulkitsinghal Aug 01 '15 at 14:04
  • Thanks, My question was regarding storing everything in a single model. – Bazinga777 Aug 02 '15 at 04:34
  • Also it's better to use a separate model in case of future updates of loopback bringing changes to the User model, or even removing it altogether – Overdrivr Nov 09 '15 at 09:40

1 Answers1

2

You can extend the built-in User model and add the details to your new model. See https://github.com/strongloop/loopback-example-access-control/blob/master/common/models/user.json#L3.

superkhau
  • 2,781
  • 18
  • 9