I have this query:
Client.select("name as dname")
Which is working fine.
Client.select("name as dname").first.dname
=> "Google"
Now I want to get all dnames as an array but pluck method does not work as dname is not column name.
2.2.5 :040 > Client.select("name as dname").pluck(:dname)
(0.6ms) SELECT dname FROM "clients"
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "dname" does not exist
How to get array of dnames? Is there any method like pluck which works on column name alias which is defined using as.
I can do this
Client.select("name as dname").map{|d| d.dname}
But looping through every record is not making any sense to me
Client.select("name as dname").map{|d| d.dname}