aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2012-09-18 03:26:07 +0300
committerSteve Klabnik <steve@steveklabnik.com>2012-09-18 03:26:11 +0300
commit143675189ef3f5518c3a2a705ab07ab1451e614e (patch)
treeefb2b2430826d93e90fa52996995537d674e4c89 /guides/source
parente2c7545cdd69376ed7e6ccb2084dda8cbd7571c2 (diff)
downloadrails-143675189ef3f5518c3a2a705ab07ab1451e614e.tar.gz
rails-143675189ef3f5518c3a2a705ab07ab1451e614e.tar.bz2
rails-143675189ef3f5518c3a2a705ab07ab1451e614e.zip
Expanded note about poly associations.
Now with example!
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/association_basics.textile15
1 files changed, 12 insertions, 3 deletions
diff --git a/guides/source/association_basics.textile b/guides/source/association_basics.textile
index e991a309ff..3ee87f642a 100644
--- a/guides/source/association_basics.textile
+++ b/guides/source/association_basics.textile
@@ -338,9 +338,18 @@ end
!images/polymorphic.png(Polymorphic Association Diagram)!
-Polymorphic associations can get tricky with inheritance. If you need
-an inheritance relationship in your ActiveRecord models, you should use
-Single Table Inheritance instead.
+Polymorphic associations can get tricky when combined with Single Table
+Inheritance. For example, given the models Parent, Child (inheriting from
+Parent) and Polymorphic (with poly_type and poly_id used to reference other
+objects), if a new Polymorphic object was to point to a object of type Child,
+the "poly_type" field would contain "Parent" instead of "Child". Assuming the
+child object had an id of 1, when querying the Polymophic model, the query
+would have to be: Polymorphic.find_by_poly_type_and_poly_id("Parent", 1) as
+opposed to Polymorphic.find_by_poly_type_and_poly_id("Child", 1).
+
+The benefit is that using "Parent" for poly_type allows you to query the
+polymorphic model for both child and parent objects instead of having to query
+individually for each child class.
h4. Self Joins