add homie to the gang when homie is created

This commit is contained in:
Bilal
2020-10-07 22:47:19 +03:00
parent 8d7716f2e0
commit 8832ba071b
9 changed files with 43 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
class AddNameToGangs < ActiveRecord::Migration[5.2]
def change
add_column :gangs, :name, :text
end
end

View File

@@ -0,0 +1,5 @@
class AddGangRelationToHomies < ActiveRecord::Migration[5.2]
def change
add_reference :homies, :gang
end
end

View File

@@ -0,0 +1,15 @@
class AddInitialGangAndConnectToHomies < ActiveRecord::Migration[5.2]
def up
# execute "INSERT INTO gangs SELECT 'name' WHERE NOT EXISTS (SELECT * FROM gangs)"
if Gang.count.zero?
Gang.create.save
end
gang = Gang.first
Homie.all.update(gang: gang)
end
def down
Homie.all.update(gang: nil)
end
end