carlo (owner)

Revisions

gist: 104553 Download_button fork
public
Public Clone URL: git://gist.github.com/104553.git
Embed All Files: show embed
Migration #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class CreateRelationships < ActiveRecord::Migration
  def self.up
    create_table :relationships do |t|
      t.integer :user_id
      t.integer :following_id
      
      t.timestamps
    end
    
    add_index( :relationships, [ :user_id, :following_id ], :unique => true )
    
  end
 
  def self.down
    drop_table :relationships
  end
end
Models #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Relationship < ActiveRecord::Base
 
  belongs_to :favourite_user, :class_name => "User", :foreign_key => "following_id"
  belongs_to :follower, :class_name => "User", :foreign_key => "user_id"
 
end
 
 
class User < ActiveRecord::Base
 
  has_many :relationships
  has_many :favourite_users, :through => :relationships
  has_many :followers, :through => :relationships
 
end