Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add in fan model and table to hold HABTM relationship to teams

  • Loading branch information...
commit adf7fc5b256aa4620c5cfb58fe45c2d1d637f192 1 parent c7169ad
@jackdempsey jackdempsey authored committed
View
5 spec/dummy_app/app/models/fan.rb
@@ -0,0 +1,5 @@
+class Fan < ActiveRecord::Base
+ validates_presence_of(:name)
+
+ has_and_belongs_to_many :teams
+end
View
1  spec/dummy_app/app/models/team.rb
@@ -10,4 +10,5 @@ class Team < ActiveRecord::Base
belongs_to(:league)
belongs_to(:division)
has_many(:players)
+ has_and_belongs_to_many :fans
end
View
12 spec/dummy_app/db/migrate/00000000000008_create_fans_migration.rb
@@ -0,0 +1,12 @@
+class CreateFansMigration < ActiveRecord::Migration
+ def self.up
+ create_table :fans do |t|
+ t.timestamps
+ t.string :name, :limit => 100, :null => false
+ end
+ end
+
+ def self.down
+ drop_table :fans
+ end
+end
View
11 spec/dummy_app/db/migrate/00000000000009_create_fans_teams_migration.rb
@@ -0,0 +1,11 @@
+class CreateFansTeamsMigration < ActiveRecord::Migration
+ def self.up
+ create_table :fans_teams, :id => false do |t|
+ t.integer :fan_id, :team_id
+ end
+ end
+
+ def self.down
+ drop_table :fans_teams
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.