From 92ff71bb14b1b589a3d5c04d120e4b9210b243b1 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 6 Jul 2010 17:29:19 +0200 Subject: documents automatic management of join models in hmt associations, in particular the gotcha that deletion is direct --- railties/guides/source/association_basics.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/guides/source') 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 + + +physician.patients = patients + + +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: -- cgit v1.2.3