ernie/squeel — Issue #89: Upgrade to squeel from meta_where fails when .order is used
Author: avinasha
Created: 2011-12-28 18:20:45+00:00
State: open

I have query like this in meta_where

`@models = Model.where(:company_id.eq => company.id).order( :last_activity_at.desc )`

I am trying to move to Squeel with the legacy support for meta_where enabled.
I get an error

```
NoMethodError:
undefined method `gsub' for #
# /Users/avinashashastry/.rvm/gems/ruby-1.9.2-p180@supportbee/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:993:in `block in distinct'
# /Users/avinashashastry/.rvm/gems/ruby-1.9.2-p180@supportbee/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:993:in `collect'
# /Users/avinashashastry/.rvm/gems/ruby-1.9.2-p180@supportbee/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:993:in `distinct'
# /Users/avinashashastry/.rvm/gems/ruby-1.9.2-p180@supportbee/gems/activerecord-3.1.3/lib/active_record/relation/finder_methods.rb:253:in `construct_limited_ids_condition'
# /Users/avinashashastry/.rvm/gems/ruby-1.9.2-p180@supportbee/gems/activerecord-3.1.3/lib/active_record/relation/finder_methods.rb:242:in `apply_join_dependency'
# /Users/avinashashastry/.rvm/gems/ruby-1.9.2-p180@supportbee/gems/activerecord-3.1.3/lib/active_record/relation/finder_methods.rb:231:in `construct_relation_for_association_find'
# /Users/avinashashastry/.rvm/gems/ruby-1.9.2-p180@supportbee/gems/activerecord-3.1.3/lib/active_record/relation/finder_methods.rb:210:in `find_with_associations'
# /Users/avinashashastry/.rvm/gems/ruby-1.9.2-p180@supportbee/gems/activerecord-3.1.3/lib/active_record/relation.rb:111:in `to_a'
# /Users/avinashashastry/.rvm/gems/ruby-1.9.2-p180@supportbee/gems/activerecord-3.1.3/lib/active_record/relation.rb:436:in `inspect' `
```

On commenting out the order clause the query runs properly. Also this query doesnt fail on `@models.to_sql` so i believe that there is no problem in sql generation. But the query fails when i do `@models.inspect`.

Any ideas?