0

Can you please suggest how to get select fields from find method ?

e.g

let params = {
        limit,
        offset,
        query: request
                };
    this.adapter.find(params)

Here, this will return all fields but instead of this I need only account_id from the resultset. I've already tried with fields inside params as well as settings{ fields: ["accout_id", "username"]} but doesn't work.

e.g

fields: ["account_id"]

Please guide me. Thanks

Nimesh
  • 3,342
  • 1
  • 28
  • 35
  • The field name for that is `attributes` so your object would need to have the same property name. http://docs.sequelizejs.com/manual/querying.html#attributes – Ellebkey Mar 27 '19 at 15:41
  • So are you suggested by this ways ? let params = { limit, offset, query: request, fields: ['account_id'] //OR attributes: ['account_id'] }; this.adapter.find(params); I've already tried with this ways but doesn't work. – Nimesh Mar 28 '19 at 04:19
  • I am having the same issue now, can you provide how you declared your `model` variable? – mhery Oct 05 '20 at 23:19

1 Answers1

0

Yes... I got the solution. I've used 'this.model' intead of 'this.adapter' like following way.

let params = {
                limit,
                offset,
                query: request
            };   

 this.model.find({
                    attributes: ['account_id'],
                    where : first_name : {
                            $like: '%Adam%'
                                }
                    })
Nimesh
  • 3,342
  • 1
  • 28
  • 35