Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Sequel gem qualified query column name with table double underscores

Tags:

ruby

sequel

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.

like image 740
lukemh Avatar asked Dec 03 '12 08:12

lukemh


1 Answers

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")
like image 127
lukemh Avatar answered Sep 20 '22 00:09

lukemh