I've added a boolean column to my active record migration
class AddIncludeInConsolidationToCompanies < ActiveRecord::Migration
def change
add_column :companies, :include_in_consolidation, :bool, :default => true
end
end
Whenever I fetch a record from the database I get "f" or "t" instead of true or false.
Is activerecord not supposed to automatically handle the type casting to and from the database.
It's like ActiveRecord::Base.connection.quoted_true/false are defaulting to true.
What is the best way around this? Ideally it should just work, a boolean column should return a boolean by default not a string.
't' and 'f' are what PostgreSQL uses for boolean values.
'bool' is not a valid datatype for a Rails migration. You need to use 'boolean'. My guess is that 'bool' is getting the column created in the database, but Rails is confused when the data is loaded into a model. Change and rerun the migration and I bet everything works out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With