Answer the question
In order to leave comments, you need to log in
ActiveRecord changing field type?
Hello. I have a table Branch -> code {11}. The value is '0000000001'. For some reason, ActiveRecord converts the field from character to numeric, and here leading zeros are important.
inst = Institution.joins( :branch ).select( 'branches.code' ).first
puts inst.code # 1
puts inst.class # FixNum
Institution.joins( :branch ).select( 'branches.code as code_branch' ).first
Branch.joins( :institutions ).select( :code )
Answer the question
In order to leave comments, you need to log in
You have an integer type field, but you enter a string value?!
The framework does the conversion itself like this:
code = '0000000001' # строка с числовым значением
puts Integer(code).inspect
code = 0b0000000011 # (число 3, включены 0-й и 1-й биты)
puts code.inspect
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question