# Eager loaiding ambiguous columns

**URL:** <https://www.ruby-forum.com/t/eager-loaiding-ambiguous-columns/141131>\
**Category:** Rails\
**Created:** [June 22, 2008, 11:37am UTC](https://www.ruby-forum.com/t/eager-loaiding-ambiguous-columns/141131 "2008-06-22T11:37:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [June 22, 2008, 11:37am UTC](https://www.ruby-forum.com/t/eager-loaiding-ambiguous-columns/141131/1 "2008-06-22T11:37:08Z")

</div>

Hi,  
I have a people table which has a first\_name,last\_name as varchar  
fields and a salutation table which also has first\_name, last\_name as a  
boolean field.

class People  
belongs\_to :salutation  
end

class Salutation  
has\_many :people  
end

The problem i have is when i try to eager load using

@people = Person.find\_all\_by\_id(params[:id],:include=\>:salutation)

I get an error “ambiguous column last\_name and first\_name”

how can i solve this problem without having to change the name of the  
column in the salutation table.

Thank you.

---

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [June 22, 2008, 11:44am UTC](https://www.ruby-forum.com/t/eager-loaiding-ambiguous-columns/141131/2 "2008-06-22T11:44:48Z")

</div>

On Jun 22, 10:37 am, Ank Ag [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem i have is when i try to eager load using
> 
> @people = Person.find\_all\_by\_id(params[:id],:include=\>:salutation)
> 
> I get an error “ambiguous column last\_name and first\_name”

are you also specifying some conditions somewhere? typically this  
means that instead of writing first\_name = ‘foo’ you need to write  
salutations.first\_name = ‘foo’ (or the other way round if your  
conditions should apply to the person’s first name).

Fred

---

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [June 22, 2008, 11:59am UTC](https://www.ruby-forum.com/t/eager-loaiding-ambiguous-columns/141131/3 "2008-06-22T11:59:11Z")

</div>

Frederick C. wrote:

> On Jun 22, 10:37ï¿½am, Ank Ag [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > The problem i have is when i try to eager load using
> > 
> > @people = Person.find\_all\_by\_id(params[:id],:include=\>:salutation)
> > 
> > I get an error “ambiguous column last\_name and first\_name”
> 
> are you also specifying some conditions somewhere? typically this  
> means that instead of writing first\_name = ‘foo’ you need to write  
> salutations.first\_name = ‘foo’ (or the other way round if your  
> conditions should apply to the person’s first name).
> 
> Fred

Hi Thank you… In the :order clause i wrote :order=\>‘last\_name’ and as  
you mentioned it should have been :order=\>‘people.last\_name’

Thanks.
