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 Message < ActiveRecord::Base | |
acts_as_nested_set :scope => 'discussable_id = #{discussable_id} AND discussable_type = \'#{discussable_type}\'' | |
belongs_to :discussable, :polymorphic => true | |
# ... | |
end | |
class Foo < ActiveRecord::Base | |
has_many :messages, :as => :discussable | |
end | |
class Bar < ActiveRecord::Base | |
has_many :messages, :as => :discussable | |
end |
By combining better_nested_set and polymorphic associations the amount of work needed to introduce a new discussable type is reduced by reducing the number of models and number of tables.
No comments:
Post a Comment