Skip to content

Instantly share code, notes, and snippets.

@colewinans
Last active December 19, 2015 03:39
Show Gist options
  • Save colewinans/5891716 to your computer and use it in GitHub Desktop.
Save colewinans/5891716 to your computer and use it in GitHub Desktop.
has_many and has_many :through?
class User < ActiveRecord::Base
has_many :subscriptions
has_many :threads, :through => :subscriptions
has_many :threads
end
class Thread < ActiveRecord::Base
has_many :subscriptions
has_many :users, :through => :subscriptions
belongs_to :user
end
class Subscription < ActiveRecord::Base
belongs_to :thread
belongs_to :user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment