jruby/activerecord-jdbc-adapter — Issue #171: ActiveRecord::JDBCError: The column 'id' was specified multiple times for 't'
Author: boxofrad
Created: 2012-02-13 16:00:26+00:00
State: open

Hi, i'm having an issue with HMT relationships on the M$SQL driver

In a rails app I have a :has_many_through relationship like so:

```ruby
class Foo
has_many :foo_bars
has_many :bars, :through => :foo_bars

def has_bar?(bar)
bars.include? bar
end
end

class Bar
end

class FooBar
belongs_to :foo
belongs_to :bar
end
```

Pretty standard stuff..

In an before filter somewhere we have a method like this:

```ruby
def require_foo_to_have_bar(bar)
redirect somewhere unless @foo.has_bar? bar
end
```

This throws an exceptions:

```
ActiveRecord::JDBCError: The column 'id' was specified multiple times for 't'.: SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY [bars].id) AS _row_num, * FROM [bars] INNER JOIN [foo_bars] ON [bars].[id] = [foo_bars].[project_id] WHERE [foo_bars].[foo_id] = 3 AND [bars].[id] = 1) AS t WHERE t._row_num BETWEEN 1 AND 1
```

I dropped the query into a SQL Server query window and the problem is that the `*` returns everything in both tables.. (including both id columns)

One way of resolving this would be to specify a table name before the `*` but i'm not sure where to apply the fix?

Thanks
- Daniel