Permalink
Browse files

create explicit memberships join table

  • Loading branch information...
bavardage committed Aug 21, 2011
1 parent 777a184 commit d52fb29a46f51d9d456586c3f5108298c363f7ba
View
@@ -0,0 +1,6 @@
+class Membership < ActiveRecord::Base
+
+ belongs_to :user
+ belongs_to :wall
+
+end
View
@@ -1,7 +1,8 @@
class User < ActiveRecord::Base
has_and_belongs_to_many :quotes
- has_and_belongs_to_many :walls
+ has_many :memberships
+ has_many :walls, :through => :memberships
has_many :authored_quotes, :class_name => "Quote", :foreign_key => "author_id"
View
@@ -1,5 +1,6 @@
class Wall < ActiveRecord::Base
- has_and_belongs_to_many :users
+ has_many :memberships
+ has_many :users, :through => :memberships
has_many :quotes
end
@@ -0,0 +1,15 @@
+class CreateMemberships < ActiveRecord::Migration
+ def self.up
+ create_table :memberships do |t|
+ t.integer :user_id, :null => false
+ t.integer :wall_id, :null => false
+ t.string :role, :null => false #member, admin, invitee, requested_to_joinee
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :memberships
+ end
+end
View
@@ -10,7 +10,15 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110815080909) do
+ActiveRecord::Schema.define(:version => 20110821040517) do
+
+ create_table "memberships", :force => true do |t|
+ t.integer "user_id", :null => false
+ t.integer "wall_id", :null => false
+ t.string "role", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
create_table "quotes", :force => true do |t|
t.integer "author_id", :null => false
@@ -0,0 +1,11 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class MembershipTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end

0 comments on commit d52fb29

Please sign in to comment.