Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

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

Closed
SampsonCrowley opened this issue Aug 11, 2017 · 2 comments
Closed

Comments

@SampsonCrowley
Copy link
Contributor

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
Copy link
Owner

thanks!
I'll publish a fix today

@PhilWaldmann
Copy link
Owner

fixed and published openrecord@1.12.4

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants