6

Using the Sequel gem:

employees = DB[:prm_master__employee.identifier]
.join(:prm_master__employee_custom_fields.identifier, :employee => :employee)
.where("termination_date >= ?","06/01/2012")
.or("termination_date = NULL")
.and("employee = 'holderl'")

The above fails with:

~/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/sequel-3.41.0/lib/sequel/adapters/tinytds.rb:221:in `fields': TinyTds::Error: Ambiguous column name 'employee'. (Sequel::DatabaseError)

I understand the error (same column names between joined tables, e.g employee), but do not know how I can qualify the employee condition in the and statement since the table uses the identifier method to ignore the underscores.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
lukemh
  • 5,043
  • 7
  • 30
  • 38
  • FYI: You're using three backticks as an attempt to mark a block of code. That doesn't work right. Use four spaces to indent instead. See the [Advanced Markdown documentation](http://stackoverflow.com/editing-help) for more information. – the Tin Man Dec 03 '12 at 16:20
  • Github markdown is far superior. the four space indent is impossible. – lukemh Feb 10 '14 at 03:17

2 Answers2

14

The answer is to actually qualify the column name using:

Sequel.qualify(:table, :column)

Or the equivalent shorter syntax:

Sequel[:table][:column]

resulting in:

employees = DB[:prm_master__employee.identifier]
.join(:prm_master__employee_custom_fields.identifier, :employee => :employee)
.where("termination_date >= ?","06/01/2012")
.or("termination_date = NULL")
.and(Sequel.qualify(:prm_master__employee_custom_fields.identifier, :employee)  => "holderl")
Gabriel Hautclocq
  • 3,230
  • 2
  • 26
  • 31
lukemh
  • 5,043
  • 7
  • 30
  • 38
0

User alias. OR put table_name.column_name

vijikumar
  • 1,805
  • 12
  • 16
  • yes i understand that, but how to do that in sequel gem when double underscore cannot be used? see my answer. – lukemh Dec 03 '12 at 08:53