문제

A basic ActiveRecord query returns an unquoted id, for example:

User.first.attributes => {"id"=>2, ...

In find_by_sql, the aliased columns are returned with values in quotes, see id in this case:

all = User.find_by_sql("SELECT u.id as u_id from users u").first.attributes => {"u_id"=>"2"}

How can the quoting of values be avoided?

도움이 되었습니까?

해결책

find_by_sql maps returned columns to object fields by name. If you return a different column name in resultset Rails have no way to know what type to return. (so it may map everything to string - wild guess)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top