Comments (7)
Take off the surrounding hash braces around :firstname.desc.
Sent from my iPhone
On Jun 15, 2011, at 5:45 PM, gucki
[email protected]
wrote:
How can I order on a column of a joined table? Is this supported? I couldn't find it documented nor by trial and error.. :(
Comment.joins(:user).order(:user => {:firstname.desc})
SELECT * FROM comments JOIN users ON (comments.user_id=users.id) ORDER BY users.firstname DESC
Reply to this email directly or view it on GitHub:
#21
from squeel.
Ups, sorry...that was a mistake. Removing the braces throws a
private method `desc' called for :firstname:Symbol
works:
PeriodicOrder.joins(:customer).order(:customer => :firstname)
fails:
PeriodicOrder.joins(:customer).order(:customer => :firstname.desc)
from squeel.
I just added specs for symbol extensions and they seem to be working for me. Did you enable them?
from squeel.
Ah, now it's working fine, thanks! I just found out I can use the new DSL for it using
order{ customer.firstname.desc }
.
But as soon as I try to make the direction dynamic using something like
order{ customer.firstname.send(direction) }
I get a "wrong number of arguments (0 for 1)" exception. How to make this working with the new DSL so I don't have to load the extensions? :)
from squeel.
Ok, finally I got it working using the new DSL:
order{ {customer => name.send(direction)} }
Sorry and thanks for squeel :-)
from squeel.
It should also work with the keypath. I'll look into it.
Sent from my iPhone
On Jun 16, 2011, at 2:58 AM, gucki
[email protected]
wrote:
Ok, finally I got it working using the new DSL:
order{ {customer => name.send(direction)} }
Sorry and thanks for squeel :-)
Reply to this email directly or view it on GitHub:
#21 (comment)
from squeel.
Managed to duplicate this. Check out the trace:
ruby-1.9.2-p180 :007 > User.joins{posts}.order{posts.id.send(:desc)}
ArgumentError: wrong number of arguments (0 for 1)
from /Users/emiller/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:932:in `desc'
Note the part about it coming from rake. Looks like it has to do with the way Rake defines a desc method in Object. Let me see if I can find a workaround. Don't bug the Rake guys on this -- they've got enough on their plate.
from squeel.
Related Issues (20)
- Using squeel with existing scopes ? HOT 1
- Literals don't work well with nil HOT 4
- Using BETWEEN condition in squeel?
- Undefined method | (pipe) HOT 2
- Accessing a records associations with a scope HOT 2
- Support for rewhere
- Group_by not working HOT 1
- Using complex IN + OR scope inside an association results in invalid SQL on join condition HOT 5
- rails 5 support HOT 18
- Support for PostgreSQL arrays
- Subquery generation when using a Relation as a parameter in regular where() HOT 4
- Performance issues HOT 1
- Default scope where conditions with or in rails 4 and squeel HOT 4
- MySQL concat function HOT 1
- makes #reorder break #last
- common table expressions (CTEs)
- Active record 5 support HOT 1
- is gem still maintained? HOT 16
- Convert column HOT 1
- Undefined method `alias_method_chain' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from squeel.