pessato
pessato

Reputation: 501

Loopback - Adding 'automatic methods' to both models for hasAndBelongsToMany relation

I am using the Strongloop API Platform and more specifically Loopback to create an api.

I have added a hasAndBelongsToMany relation to Model1 with Model2.

Works great, Model1 now has a bunch of methods added to it for different querying and CRUD operations.

I would now like to have these same methods added to Model2 so I can query and perform CRUD operations the other way.

Is this easily done out of the box using Loopback?

If not the only options I feel I have are:

  1. Create another hasAndBelongsToMany relation the other way which would result in another table being created and a lot of duplicate data.

  2. Create custom methods for Model2 which access the methods from Model1 and will essentially do the same as these automatically generated methods.

Any help greatly appreciated, thanks in advance.

Upvotes: 2

Views: 278

Answers (1)

Bakh Domalak
Bakh Domalak

Reputation: 71

Just use your option 1 - create hasAndBelongsToMany relation for Model2 with Model1. Don't worry, another table will not be created. Loopback is smart enough to not do so ;)

Upvotes: 1

Related Questions