0

I have this query:

UserModel.find({

    filter: {
        include: 
        [
            "communications",
             "roles"
        ],
        where : {
            "object_type" : 1
        }
    } 
}, function(data){
    $rootScope.users = data;
});

I want to get all the data from communications model filter by the field "object_type" but it doesn't work as I want.

My Communications model looks like this:

...
"properties": {
"object_type": {
  "type": "number"
},
"object_id": {
  "type": "number"
},
"communications_type_code": {
  "type": "number"
},
"address_type": {
  "type": "number"
},
"contact_value": {
  "type": "string"
},
"notes": {
  "type": "string"
},
....

2 Answers 2

1

To query related models you have to use relation scope. In your case that would be something like this:

UserModel.find({
    filter: {
        include: 
        [
            {
              "relation": "communications",
              "scope": { 
                "where": {"object_type": 1}
              }

            },
            "roles"
        ]
    } 
}, function(data){
    $rootScope.users = data;
});

Check the docs about "Querying related models"

Sign up to request clarification or add additional context in comments.

Comments

0

Oded, I believe you do not need the filter property in the search parameter. It should read like this:

UserModel.find({
    include: [ "communications", "roles" ],
    where : { "object_type" : 1 }
}, function(data){
    $rootScope.users = data;
});

Also make sure that the other entities that you add to include have a relationship to the queried model. Is it really UserModel or should it be CommunicationsModel?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.