Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if search then return empty object instead of omit #2090

Open
durai001 opened this issue Nov 3, 2020 · 1 comment
Open

if search then return empty object instead of omit #2090

durai001 opened this issue Nov 3, 2020 · 1 comment

Comments

@durai001
Copy link

durai001 commented Nov 3, 2020

Problem

if search child ( with related table) if there is no value then the whole JSON result should omit but I'm getting the empty object. thanks in advance

Issue Description

let say if I have a process table and user table. I am fetching the processing table with belongs to user table. below is the sample response

{
 {
        "id": 1,
        "process_id": 1,
        "description": "activity1-1-1",
        "user": {
            "id":1,
            "name": "durai"    
        }
    },
 {
        "id": 1,
        "process_id": 1,
        "description": "activity1-1-1",
         "user": {
            "id":2,
            "name": "vinoth"    
        }
    },
}

Expected behavior

the first process object is removed because I search with vinoth.The whole process object is needed to be removed

{
 {
        "id": 1,
        "process_id": 1,
        "description": "activity1-1-1",
         "user": {
            "id":2,
            "name": "vinoth"    
        }
    },
}

Actual behavior

If I search username "vinoth" then it's giving the empty object of other objects but I need that should be omitted.

{
 {
        "id": 1,
        "process_id": 1,
        "description": "activity1-1-1",
        "user": {},
    },
 {
        "id": 1,
        "process_id": 1,
        "description": "activity1-1-1",
         "user": {
            "id":2,
            "name": "vinoth"    
        }
    },
}

Here is the code

get_process: function (req, res) {
   process.where({
     id: req.params.id
   }).fetchAll({
     withRelated: [{
       "user": query => {
             if (search) {
               return query.where('name', 'LIKE', '%' + search + '%')
             }},
     }],
   }).then(function (process) {
     successHandler(200, process, res);
   })["catch"](function (err) {
     failureHandler(204, err, res);
   });
 },
@durai001
Copy link
Author

My problem is if there is no data in relation then we should omit that whole process object not just like user kay . we no need that process details if there is no user with I searched

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant