Sequelize ordering with nested associations

43
May 15, 2019, at 8:50 PM

I have an included model where I need to sort by the same property but with two conditionals.

 include:[{
      model: EventType,
      include: { model: EventType, as: 'parent' },
 }],

They have property parentId in the DB and when data is read it looks like this

If it has parent:

eventType: {
  name: 'Some other name' // this is default name prop same as parents
  parentId: 1,
  parent: { name: 'Somename' }
}

If not

eventType: {
  name: 'another name'
  parentId: null,
  parent: null
}

I want to sort by name, but if eventType has 'parent' to use parents name for sorting.

My ordering property looks like this:

order: [
 [{ model: EventType, as: 'parent' }, 'name', sorting],
 [{ model: EventType }, 'name', sorting],
]

So this is always looking just name property and looking for parent's name. Does anyone knows what could be the problem?

READ ALSO
Node app segfault on Heroku: std::bad_alloc and exit code 134

Node app segfault on Heroku: std::bad_alloc and exit code 134

I am having difficulty understanding this heroku stack traceMy app has been running very well both locally and in Heroku for a few years now

24
socket.io is not working with simple-peer

socket.io is not working with simple-peer

i am willing to build one-to-one video chatroom with Socketio & Simple-Peer and for one-to-one algorithm i used socket

23
ORM for oracle DB in nodejs

ORM for oracle DB in nodejs

could you please suggest me better ORM for Oracle DB ?

39
Get loopback models using loopback-datasource-juggler

Get loopback models using loopback-datasource-juggler

Is there any other way other than getting the loopback model by using app object in a custom js file?

15