ruby - Populating Rails table with seeds file - where seed data has a 'false' for intended value in a boolean column, record is not loading -
running rails 4.2, postgres 9.1 on local development machine. attempting seed table 5 rows, 5 columns on each row. 1 of columns boolean value. problem can't seem load records boolean value not true. following schema:
create_table "institution_types", force: :cascade |t| t.string "institution_type" t.string "institution_code" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "ownership" t.integer "term" t.boolean "nonprofit" end
in seeds.rb file have:
institution_types = [ ["public 4 year", "p4", "public", 4, true], ["public 2 year", "p2", "public", 2, true], ["private 4 year profit", "r4p", "private", 4, false], ["private 2 year profit", "r2p", "private", 2, false], ["private 4 year nonprofit", "r4np", "private", 4, true], ["private 2 year nonprofit", "r2np", "private", 2, true] ] institution_types.each |type, code, ownership, term, nonprofit| institutiontype.create(institution_type: type, institution_code: code, ownership: ownership, term: term, nonprofit: nonprofit) end
note have attempted variants with:
- quotes around boolean values nonprofit column (i.e. "true", "false")
- nothing declared nonprofit column on 2 records setting false (i.e.
["private 4 year profit", "r4p", "private", 4]
- 'nil' declared instead of 'false'
regardless of how attempt load data database, i'm getting records value nonprofit column true. in other words, first two, , last two, in institution_types variable declared above.
this frustrating, , far none of searches on interwebs or stack overflow yielding solutions. suppose load records "true" go db directly , change records sql...but that's dumb.
alternative going ditching boolean value nonprofit column , stating "profit" or "nonprofit" 2 options. but...before (or if turns out best course) i'd know bigger picture rules around getting boolean data database using seeds.rb.
this block silently discarding information need:
institution_types.each |type, code, ownership, term, nonprofit| institutiontype.create(institution_type: type, institution_code: code, ownership: ownership, term: term, nonprofit: nonprofit) end
change create
create!
, throw, telling issue.
Comments
Post a Comment