Git Product home page Git Product logo

Comments (7)

ernie avatar ernie commented on August 14, 2024

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.

gucki avatar gucki commented on August 14, 2024

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.

ernie avatar ernie commented on August 14, 2024

I just added specs for symbol extensions and they seem to be working for me. Did you enable them?

from squeel.

gucki avatar gucki commented on August 14, 2024

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.

gucki avatar gucki commented on August 14, 2024

Ok, finally I got it working using the new DSL:

order{ {customer => name.send(direction)} }

Sorry and thanks for squeel :-)

from squeel.

ernie avatar ernie commented on August 14, 2024

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.

ernie avatar ernie commented on August 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.