From f023cb1a6ea62069c0f2791b1b479a43e3e1275d Mon Sep 17 00:00:00 2001 From: Niklas Date: Sat, 28 Oct 2017 17:30:32 +0200 Subject: [PATCH] Update README with STI rebuild! behavior Description on how to work around STI subclasses remove other subclasses hierarchies when calling Subclass.rebuild! method. --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 8185dc4b..78ae950a 100644 --- a/README.md +++ b/README.md @@ -389,6 +389,18 @@ class WhereTag < Tag ; end class WhatTag < Tag ; end ``` +Note that if you call `rebuild!` on any of the subclasses, the complete Tag hierarchy will be emptied, thus taking the hiearchies of all other subclasses with it (issue #275). However, only the hierarchies for the class `rebuild!` was called on will be rebuilt, leaving the other subclasses without hierarchy entries. + +You can work around that by overloading the `rebuild!` class method in all your STI subclasses and call the super classes `rebuild!` method: +```ruby +class WhatTag < Tag + def self.rebuild! + Tag.rebuild! + end +end +``` +This way, the complete hierarchy including all subclasses will be rebuilt. + ## Deterministic ordering By default, children will be ordered by your database engine, which may not be what you want.