Bikash Lama
Bikash Lama

Reputation: 187

Access relationship table in loopback

We have a relationship table built with the below relationship between models.
https://loopback.io/doc/en/lb3/HasAndBelongsToMany-relations.html
Though we can access the related model via the model instance. I am wondering how we can access the relationship table directly as I want to filter the records from the relationship table's custom field that we have added later in that relationship table.

For an example, after creating a new column (createdat) on AssemblyPart table, I would like to filter the record based on createdat columns.

At the moment, we are using execute method of connector to execute raw sql to access this relationship table.

Upvotes: 1

Views: 48

Answers (1)

Amar Bisht
Amar Bisht

Reputation: 137

Use app to access all models individually if they aren't related to User Model: Reference:

var app = require('../../server/server'); 
var ModelName = app.models.ModelName;
ModelName.find().then(data=>
{
 // Your Data
}).catch(error=>
{
 // error
})

Upvotes: 0

Related Questions