Problem with Joins :(

@document_pages, @documents = paginate :documents, :per_page => 20,
:joins => “LEFT JOIN companies ON companies.id = documents.company_id”,
:conditions => “doc_type_id = ‘#{@doc_type_id}’”, :order =>
“companies.name asc”

The problem with this segment of code is that when I try to display a
document’s ID number, it displays the companies’ ID number, since the
join overwrites @documents.id with companies.id.

How can I prevent this?

Thanks,
Ben L.

Ben L. wrote:

@document_pages, @documents = paginate :documents, :per_page => 20,
:joins => “LEFT JOIN companies ON companies.id = documents.company_id”,
:conditions => “doc_type_id = ‘#{@doc_type_id}’”, :order =>
“companies.name asc”

The problem with this segment of code is that when I try to display a
document’s ID number, it displays the companies’ ID number, since the
join overwrites @documents.id with companies.id.

How can I prevent this?

Thanks,
Ben L.

If you are doing the join just so that you can sort on companies.name,
then I suppose the easiest thing is to use :select => ‘documents.*’

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs