validate models for uniqueness of id

11 views
Skip to first unread message

ashcs...@gmail.com

unread,
Oct 18, 2017, 4:20:54 AM10/18/17
to LoopbackJS
Hi All,

I have a an Account and Customer model. An account can have many customers, but want to restrict it 2 only. I am trying to use the following validation to check uniqueness of account-id but it does not work.


Customer.validatesUniquenessOf('account-id', {message: 'Profile already exists'});

As of now, when I hit the POST customers request with the following payload, it keeps creating multiple customers with the same account-id.

{
 
"account-id": "59ddf55905bef63cfc127b18",
 
"age": 25,
 
"about-me": "this is test description"
}


How do I implement this validation on Customer model ?

Thanks
Reply all
Reply to author
Forward
0 new messages