diff --git a/app/models/skill.rb b/app/models/skill.rb index 1b4b4a9d..4fd5049b 100644 --- a/app/models/skill.rb +++ b/app/models/skill.rb @@ -5,7 +5,7 @@ class Skill < ActiveRecord::Base BLANK = '' belongs_to :user - has_many :endorsements + has_many :endorsements, dependent: :delete_all validates_presence_of :tokenized validates_presence_of :user_id diff --git a/db/migrate/20150108152023_cleanup_endorsements_without_skill.rb b/db/migrate/20150108152023_cleanup_endorsements_without_skill.rb new file mode 100644 index 00000000..10becd3d --- /dev/null +++ b/db/migrate/20150108152023_cleanup_endorsements_without_skill.rb @@ -0,0 +1,9 @@ +class CleanupEndorsementsWithoutSkill < ActiveRecord::Migration + def up + Endorsement.delete_all(skill_id: [nil,'']) + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index 71863f0c..7c3a39e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150103105333) do +ActiveRecord::Schema.define(:version => 20150108152023) do add_extension "citext" add_extension "hstore"