Skip to content

Instantly share code, notes, and snippets.

@jfeust
Created April 28, 2011 14:17
Show Gist options
  • Save jfeust/946426 to your computer and use it in GitHub Desktop.
Save jfeust/946426 to your computer and use it in GitHub Desktop.
Polymorphic Question
class Picture < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true
end
class Employee < ActiveRecord::Base
has_many :pictures, :as => :imageable
end
class Product < ActiveRecord::Base
has_many :pictures, :as => :imageable
end
# vs
class Picture < ActiveRecord::Base
belongs_to :employee
belongs_to :product
end
class Employee < ActiveRecord::Base
has_many :pictures
end
class Product < ActiveRecord::Base
has_many :pictures
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment