使用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'")
上述内容失败了:
~/.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)
我理解错误(连接表之间的相同列名,例如员工),但不知道如何在and
语句中限定员工条件,因为表使用标识符方法忽略下划线。
答案 0 :(得分:12)
答案是使用以下方法实际限定列名:
Sequel.qualify(:table, :column)
导致:
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")
答案 1 :(得分:0)
用户别名。或者把table_name.column_name