1

On the client side as of now, it receives an array of record labels from the database. The code below is the query used with Sequelize to call all record labels.

I do receive an array in order by names (strings), but

the array is case sensitive, therefore if the name is capital is will be in the beginning of the array. I will give in an example of what it outputs:

currently:

A

B

C

D

a

b

c

d

but I'm trying to get it to return like this

A

a

B

b

C

c

D

d

If all else fails, I will just make some logic on the client side, but any suggestions would be appreciated.

router.get('/', function (req, res) {
  RecordLabel.findAll({
    order: ('name').toUpperCase()
  })
  .then(function (recordLabels) {
    return res.json(recordLabels)
  })
  .catch(function (err) {
    return res.json({ error: err})
  })
})
Kai Keanaaina
  • 73
  • 1
  • 10

2 Answers2

1

This order problem is not deriving from sequelize but postgresql. In some configurations posstgresql is not ordering even by primary key or id. If you have priviliages, changing database locales can work for you.

After a query has produced an output table (after the select list has been processed) it can optionally be sorted. If sorting is not chosen, the rows will be returned in an unspecified order. The actual order in that case will depend on the scan and join plan types and the order on disk, but it must not be relied on. A particular output ordering can only be guaranteed if the sort step is explicitly chosen.

Look at this answer : link

Community
  • 1
  • 1
osmanraifgunes
  • 1,438
  • 2
  • 17
  • 43
1

enter image description hereuse this :

router.get('/', function (req, res) {
var sequelize=require('sequelize')
RecordLabel.findAll({
  order:[sequelize.fn('lower', sequelize.col('name'))]
})
.then(function (recordLabels) {
   return res.json(recordLabels)
})
.catch(function (err) {
  return res.json({ error: err})
  })
})
farhadamjady
  • 982
  • 6
  • 14