PhilWaldmann / openrecord

Make ORMs great again!
https://openrecord.js.org
MIT License
486 stars 38 forks source link

order with multiple columns causes `attribute.split` is not a function #54

Closed SampsonCrowley closed 7 years ago

SampsonCrowley commented 7 years ago

If i try to order by multiple columns WORKS

School
      .select('schools.id as id', 'name', 'address.city as city', 'address_state.abbr as state')
      .join({address: 'state'}, 'inner')
      .order('name')

ERROR

School
      .select('schools.id as id', 'name', 'address.city as city', 'address_state.abbr as state')
      .join({address: 'state'}, 'inner')
      .order(['name', 'city'])

I get the error:

TypeError: attribute.split is not a function
    at Array.<anonymous> (/home/samps/sites/personal/dus/office.downundersports.com/node/node_modules/openrecord/lib/stores/sql/order.js:68:31)

sql/order.js

...
...
order: function(columns, desc){
    var self = this.chain()

    if(columns){
      if(typeof desc === 'boolean'){
        if(!Array.isArray(columns)) columns = [columns]
      }else{
        columns = Utils.args(arguments)
        desc = false
      }

      for(var i in columns){ 
        //MOST LIKELY NOT PROPERLY ADDING TO INTERNAL HERE
        self.addInternal('order', {column: columns[i], order: desc ? 'DESC' : 'ASC'})
      }
    }else{
      self.clearInternal('order')
    }

    return self
  },
...
...
exports.definition = {
  mixinCallback: function(){
    this.beforeFind(function(query){
      var order = this.getInternal('order')
...
...
      for(i in order){
          var attribute = order[i].column
          var tmp = attribute.split('.') //ERROR IS HERE
...
...
}
PhilWaldmann commented 7 years ago

thanks! I'll publish a fix today

PhilWaldmann commented 7 years ago

fixed and published openrecord@1.12.4