Can some Rails expert throw some light on this behaviour in Rails 4:
>query_string = "agent_id = '1'"
=> "agent_id = '1'"
>Lead.includes('agents').where(query_string).length
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'agent_id' in 'where clause'
>Lead.includes('agents').where(agent_id = '1').length
Lead Load (0.5ms) SELECT `leads`.* FROM `leads` WHERE (1)
LeadsAssignment Load (0.4ms) SELECT `leads_assignments`.* FROM `leads_assignments` WHERE `leads_assignments`.`lead_id` IN (1, 2, 3, 4, 5)
Agent Load (0.5ms) SELECT `agents`.* FROM `agents` WHERE `agents`.`id` IN (1, 2)
=> 5
The two queries should be identical. Why would one fail and the other not?
Thanks! Charlie
Lead.includes('agents').where(agent_id = '1').lengthis not even valid syntax and can not workagent_id, assigning'1'to it, then using that to executewhere('1')...which is valid, it's just going to match every row.