I have a fairly straightforward question in Rails 3 to which I can't seem to find the answer:
Let's say I have 2 models: Customer, Project.
A Customer has_many projects
Project belongs_to customer
Now I want to sort a list of projects by "customer name" using Active Record (doing it with a Ruby array is easy enough, but I imagine this will get problematic once the number of project records grows).
How do I go about doing this with ActiveRecord?
Project.joins(:customer).order('customers.name')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With