I am getting the error below when trying to query my PostgreSQL database. I can view the table and all columns in pgAdmin and even perform a select *, so I know the table and column exists. Any help with this will be greatly appreciated.
Here is the error I am getting:
PG::Error: ERROR: column "fi_ase" does not exist
Here is the schema for the table in question. It was generated with a migration as part of a Rails 3.2 app.
create_table "certificates", :force => true do |t|
t.integer "profile_id"
t.boolean "FI_ASE"
t.boolean "FI_AME"
t.boolean "FI_INSTA"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "C_ASEL"
t.boolean "C_AMEL"
t.boolean "C_ASES"
t.boolean "C_AMES"
t.boolean "ATP_ASEL"
t.boolean "ATP_AMEL"
t.boolean "ATP_ASES"
t.boolean "ATP_AMES"
t.boolean "GI_Basic"
t.boolean "GI_Advanced"
t.boolean "GI_Instrument"
end
Here is my query/method in Rails:
def self.search(city, state, zip, *certs)
query_obj = joins(:profile => [:addresses, :certificate])
query_obj = query_obj.where("city like ?", "%#{city}%") unless city.blank?
query_obj = query_obj.where("state = ?", state) unless state.blank?
query_obj = query_obj.where("zip like ?", "%#{zip}%") unless zip.blank?
query_obj = query_obj.where("FI_ASE = ?", true) unless certs[0].blank?
query_obj
end
I get the same error when running the following SQL statement directly in my pgAmin SQL Editor:
select *
from contacts c
inner join profiles p on c.id = p.contact_id
inner join addresses a on p.id = a.profile_id
inner join certificates ct on p.id = ct.profile_id
where ct.FI_ASE = true