join will work, even :include will work.
but this reduce performance for query.

On Apr 23, 12:01 pm, Anubhaw Prakash <[email protected]> wrote:
> Sumeet Panchal wrote:
> > Hi,
>
> > I am stuck pretty bad please help. any comment is helpful.
> > I have say three models
> > Customer(fields are id, name, cell_phone, primary_address_id)
> >    belongs_to :primary_address, :class_name =>
> > 'CustomerAddress', :foreign_key => 'primary_address_id'
> >    has_many :customer_addresses
> > end
>
> > CustomerAddress(fields city, customer_id, state)
> >    belongs_to :customer
> > end
>
> > so basically I have many addresses for a customer, and one of which is
> > primary address. so I have this relations ship
> > customer.primary_address.
>
> > Now I want to write a query by using find or paginate. like:
> > Customer.find [arra of id], :order => "primary_address.city ASC"
> > The problem is that it is notorderingbyassociatedcolumns. It says
> > no column primary_address.city found.
> > I am trying to use include but it do not works, :join how can I use
> > it. Please help is there any way to order byassociatedcolumns.
>
> > Thanks
> > Sumeet Panchal
>
> You can use join as Customer.find(:all, :joins => "customers inner join
> customer_address as b on customers.primary_address_id=b.id") and in this
> you can useordering.
>
> Anubhaw
> --
> Posted viahttp://www.ruby-forum.com/.
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/rubyonrails-talk?hl=en.

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to