I have models Client and Sessions and a join model ClientSessionAssignment that associates the two. ClientSessionAssignment has one join column score which is defined as decimal type in schema.rb. I'm using has_many with select to preload score values when querying instances of Client as follows:
class Client < ActiveRecord::Base
has_many :sessions,
:through => :client_session_assignments,
:select => 'sessions.*, client_session_assignments.score'
end
Despite score being defined as decimal in the database, when it is accessed this way, Active Record represents it as a string, i.e. Client.first.sessions.first.score.class yields String when I would expect it to yield BigDecimal. Consequently, I have to cast or convert scores obtained this way to BigDecimal before I can perform any calculations on them.
UPDATES
It turns out that only the postgresql database adapter exhibits this strange behaviour. I have filed https://github.com/rails/rails/issues/13044 to track this in the Rails bug tracker on GitHub: full test case is at https://gist.github.com/rcook/7670071.
:selectoption, thenscoreis not added toClient.first.sessions.first.BigDecimal.BigDecimalcalling through associations)