From 8803508751837d96fd0beff60c952fb2044d073f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 15 Sep 2013 12:46:09 +0200 Subject: Cleanup polymorphic base tables when dropping derived one --- evolution/drop-table/model.hxx | 51 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'evolution/drop-table/model.hxx') diff --git a/evolution/drop-table/model.hxx b/evolution/drop-table/model.hxx index 64022bb..55035e6 100644 --- a/evolution/drop-table/model.hxx +++ b/evolution/drop-table/model.hxx @@ -29,11 +29,7 @@ namespace MODEL_NAMESPACE(MODEL_VERSION) std::string str; }; -#if MODEL_VERSION > 1 #pragma db object -#if MODEL_VERSION == 3 - #pragma db deleted(3) -#endif struct object1 { object1 (): o (0) {} @@ -45,6 +41,53 @@ namespace MODEL_NAMESPACE(MODEL_VERSION) object* o; std::vector nums; }; + +#if MODEL_VERSION == 3 + #pragma db object(object1) deleted(3) +#endif + + // Make sure we also clean up base tables when dropping a + // table corresponding to the polymorphic derived object. + // + #pragma db value + struct value + { + value (unsigned long n = 0, const std::string& s = ""): num (n), str (s) {} + + unsigned long num; + std::string str; + }; + + #pragma db object polymorphic + struct root + { + root (unsigned long n = 0, const std::string& s = ""): id (n, s) {} + virtual ~root () {} + + #pragma db id + value id; + }; + + #pragma db object + struct base: root + { + base (unsigned long n = 0, const std::string& s = "") + : root (n, s), num (n) {} + + unsigned long num; + }; + + #pragma db object + struct derived: base + { + derived (unsigned long n = 0, const std::string& s = "") + : base (n, s), str (s) {} + + std::string str; + }; + +#if MODEL_VERSION == 3 + #pragma db object(derived) deleted(3) #endif } -- cgit v1.1