Noah
Noah

Reputation: 4751

Using select on JSON field in Sequeilze

I'd like to find some items, but return only one field (name) from a JSON field (body). The JSON field is also in an association (Version), if that matters.

I imagine it would be something like this.

Part.findAll({
  attributes: ['slug'],
  include : [{
    model: Version,
    limit: 1,
    order: [['createdAt', 'DESC']],
    attributes: ['body.name']
  }]
})

Upvotes: 1

Views: 58

Answers (1)

Pratyush Vashisht
Pratyush Vashisht

Reputation: 182

I wanted to write a comment but I can't because I don't have enough reputation. So can't you just retrieve the body and from the results, get the required attributes of the JSON.

Upvotes: 1

Related Questions