Ambiguous clause error

I’m trying to query one table to ultimately display the relate info from
another table. I have 2 tables: “posts” and “numbers”. I’m trying to do
a query like this:

@numbers = Number.find(:all,
:conditions => [ ‘(user_id) = :id’,
{:id => @session[‘user’].id}],
:include => :post)

Then display it like this:

    <% for number in @numbers do %>
  • <%= link_to number.post.title, :controller => 'post', :action => 'show', :id => post %> Ending: <%= number.post.end_date %>
  • <% end %>

I’m getting “Column ‘user_id’ in where clause is ambiguous” From the
reading I’ve been doing it seems the fact that there is a “user_id”
field in both tables might be the issue. How do I work around this? Do I
have to rename one of the “user_id” columns, or is there a more elegant
way of doing this?

Jasbur wrote:

I’m trying to query one table to ultimately display the relate info from
another table. I have 2 tables: “posts” and “numbers”. I’m trying to do
a query like this:

@numbers = Number.find(:all,
:conditions => [ ‘(user_id) = :id’,
{:id => @session[‘user’].id}],
:include => :post)

Then display it like this:

    <% for number in @numbers do %>
  • <%= link_to number.post.title, :controller => 'post', :action => 'show', :id => post %> Ending: <%= number.post.end_date %>
  • <% end %>

I’m getting “Column ‘user_id’ in where clause is ambiguous” From the
reading I’ve been doing it seems the fact that there is a “user_id”
field in both tables might be the issue. How do I work around this? Do I
have to rename one of the “user_id” columns, or is there a more elegant
way of doing this?

When you invlolve more than one table you usually have to specify the
table name in the sql. Try this:

:conditions => [ ‘(numbers.user_id) = :id’, {:id =>
@session[‘user’].id}]

That was it. Actually I just found it in the Agile book right before I
saw your reply. Thanks for the help.