On 17 June 2014 13:34, Ronald Fischer <[email protected]> wrote:
> I have in my model
>
> class Card < ActiveRecord::Base
>   has_many  :idioms,    dependent: :destroy
> end
>
> class Idiom < ActiveRecord::Base
>   belongs_to :card
> end
>
> In my schema, Idiom has an integer column kind. Given a certain card, I
> would like to have all associated idioms, but sorted in descending order
> according to the 'kind' column.
>
> I could do a
>
>   @card.idioms.sort { .... }
>
> but would prefer doing the sorting by the time the data is retrieved
> from the database. I googled two suggestions:
>
> (1) @card.idioms(:order => 'kind DESC')
>
> This doesn't seem to have any effect.

What do you mean by not having any effect?  It did not find anything,
or they were not sorted correctly?
If you have a look in log/development.log you will see the query being
run and check that it looks ok.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuBjaezUUz5%3Dtw_SKY83wUNNG9nkybvFPZK2RKbK2Ok5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to