fix mysql '0000-00-00 00:00:00' default on hats.doffed_at

Fixes #451
This commit is contained in:
Peter Bhat Harkins 2018-01-31 15:32:11 -06:00
parent 9655df14a9
commit 826c88f157
3 changed files with 8 additions and 4 deletions

View File

@ -31,9 +31,7 @@ class User < ActiveRecord::Base
:through => :votes,
:source => :story
has_many :hats
has_many :wearable_hats,
-> { where('hats.doffed_at' => nil) },
:class_name => "Hat"
has_many :wearable_hats, -> { where('doffed_at is null') }, :class_name => "Hat"
has_secure_password

View File

@ -0,0 +1,6 @@
class FixDoffedAt < ActiveRecord::Migration[5.1]
def change
change_column_default :hats, :doffed_at, nil
Hat.where("doffed_at = ?", "0000-00-00 00:00:00").update_all(:doffed_at => nil)
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180131170318) do
ActiveRecord::Schema.define(version: 20180131203555) do
create_table "comments", id: :integer, unsigned: true, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" do |t|
t.datetime "created_at", null: false