Skip to content

Instantly share code, notes, and snippets.

@davidcelis
Created February 20, 2012 20:35
Show Gist options
  • Save davidcelis/1871246 to your computer and use it in GitHub Desktop.
Save davidcelis/1871246 to your computer and use it in GitHub Desktop.
Polymorphism 101
class Post < ActiveRecord::Base
has_many :tag_links
has_many :tags, :through => :tag_links
# ...
end
class Project < ActiveRecord::Base
has_many :tag_links
has_many :tags, :through => :tag_links
# ...
end
# Schema info:
#
# t.string :name
class Tag < ActiveRecord::Base
has_many :tag_links
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment