aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/association_basics.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-07-06 17:29:19 +0200
committerXavier Noria <fxn@hashref.com>2010-07-06 17:29:34 +0200
commit92ff71bb14b1b589a3d5c04d120e4b9210b243b1 (patch)
treeb9921c7228d35525ddc086b9f11e993abf284fa4 /railties/guides/source/association_basics.textile
parent8079484b118e6dc8ffe3575b50c3857acd5b1a6d (diff)
downloadrails-92ff71bb14b1b589a3d5c04d120e4b9210b243b1.tar.gz
rails-92ff71bb14b1b589a3d5c04d120e4b9210b243b1.tar.bz2
rails-92ff71bb14b1b589a3d5c04d120e4b9210b243b1.zip
documents automatic management of join models in hmt associations, in particular the gotcha that deletion is direct
Diffstat (limited to 'railties/guides/source/association_basics.textile')
-rw-r--r--railties/guides/source/association_basics.textile10
1 files changed, 10 insertions, 0 deletions
diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile
index 335d17579d..c69f2ae8c9 100644
--- a/railties/guides/source/association_basics.textile
+++ b/railties/guides/source/association_basics.textile
@@ -137,6 +137,16 @@ end
!images/has_many_through.png(has_many :through Association Diagram)!
+The collection of join models can be managed via the API. For example, if you assign
+
+<ruby>
+physician.patients = patients
+</ruby>
+
+new join models are created for newly associated objects, and if some are gone their rows are deleted.
+
+WARNING: Automatic deletion of join models is direct, no destroy callbacks are triggered.
+
The +has_many :through+ association is also useful for setting up "shortcuts" through nested +has_many+ associations. For example, if a document has many sections, and a section has many paragraphs, you may sometimes want to get a simple collection of all paragraphs in the document. You could set that up this way:
<ruby>