Tuesday, 4 April 2017

"or" filter for nested relations in loopback find query

I have a query like:

Members.app.models.MobileUserAlertRelation.find({where: {userId: userId}, include: {relation: "alerts", scope: {where: {title: 'testng'}, include: {relation: "alertTypes", scope: {where: {alertTypeName: "test"}}}}}}, function(err, result) {
        console.log(result);
});

Here MobileUserAlertRelation model has a relation "alerts" and alerts model has a relation "alertTypes". What I am trying to achieve is: find where title field in alerts is "testng" or alertTypeName field in alertTypes is "test".

Table structure is like:
MobileUserAlertRelation: fields {id, userId, alertId}
Alerts: fields {id, title, alertTypeId}
AlertTypes: fields {id, alertTypeName}

ie. AlertType relation is nested inside alert relation. How can this be done? Any help would be appreciated. Please let me know if more clarification is required.



via DevStar

No comments:

Post a Comment