Created
April 28, 2011 14:17
-
-
Save jfeust/946426 to your computer and use it in GitHub Desktop.
Polymorphic Question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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