I have two tables in a one-to-one relationship. Let''s call them
orders and invoices. In the "list" page for "invoices", how
do I setup
my find so I can display them in order of "created_at" dates of the
"orders" table, instead of "created_at" of the
"invoices" table?
I thought I could do something like this, but it returns "no method
error".
@invoices = Invoice.find(:all).order.find(:all, :order =>
''created_at
DESC'')
or
@invoices = Invoice.find(:all, :order => "#{Invoice.order.created_at}
DESC")
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Sep-14 19:00 UTC
Re: Order a Find Based on Attribute of Related Table
> I have two tables in a one-to-one relationship. Let''s call them > orders and invoices. In the "list" page for "invoices", how do I setup > my find so I can display them in order of "created_at" dates of the > "orders" table, instead of "created_at" of the "invoices" table? > > I thought I could do something like this, but it returns "no method > error". > > @invoices = Invoice.find(:all).order.find(:all, :order => ''created_at > DESC'') > > or > > @invoices = Invoice.find(:all, :order => "#{Invoice.order.created_at} > DESC")Invoice.find(:all, :include => [:orders], :order => ''orders.created_at DESC'') --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You Rock!! On Sep 14, 3:00 pm, Philip Hallstrom <ra...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > I have two tables in a one-to-one relationship. Let''s call them > > orders and invoices. In the "list" page for "invoices", how do I setup > > my find so I can display them in order of "created_at" dates of the > > "orders" table, instead of "created_at" of the "invoices" table? > > > I thought I could do something like this, but it returns "no method > > error". > > > @invoices = Invoice.find(:all).order.find(:all, :order => ''created_at > > DESC'') > > > or > > > @invoices = Invoice.find(:all, :order => "#{Invoice.order.created_at} > > DESC") > > Invoice.find(:all, :include => [:orders], :order => ''orders.created_at > DESC'')--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---