README.rdoc in polymorphic_identity-0.1.0 vs README.rdoc in polymorphic_identity-0.1.1
- old
+ new
@@ -26,12 +26,11 @@
Polymorphic associations are not very descriptive when it comes to easily
knowing the type of model your interacting with. For example, a typical
polymorphic assocation looks like the following:
class Tag < ActiveRecord::Base
- belongs_to :taggable,
- :polymorphic => true
+ belongs_to :taggable, :polymorphic => true
end
When getting the taggable record, you would normally have to call
<tt>tag.taggable</tt>. However, if you know that the taggable record is just an
instance of the Article model, then it would feel more comfortable if you could
@@ -43,22 +42,19 @@
== Usage
=== Example
class Comment < ActiveRecord::Base
- belongs_to :commentable,
- :polymorphic => true
- belongs_to :commenter,
- :polymorphic => true
+ belongs_to :commentable, :polymorphic => true
+ belongs_to :commenter, :polymorphic => true
end
class Article < ActiveRecord::Base
has_many :comments, :as => :commentable
end
class User < ActiveRecord::Base
- has_many :comments,
- :as => :commenter
+ has_many :comments, :as => :commenter
end
c = Comment.find(1) # => #<Tag id: 1, commentable_id: 1, commentable_type: "Article", commenter_id: 1, commenter_type: "User"}>
c.commentable # => #<Article id: 1>
c.article # => #<Article id: 1>