diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-15 12:46:09 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-17 12:04:03 +0200 |
commit | 8803508751837d96fd0beff60c952fb2044d073f (patch) | |
tree | 7b14fdc13d2d9ef67c7731f6bce68e18f6956cca /evolution/drop-table/model.hxx | |
parent | 86a83893351adef44574514c303aa880cf3b6d54 (diff) |
Cleanup polymorphic base tables when dropping derived one
Diffstat (limited to 'evolution/drop-table/model.hxx')
-rw-r--r-- | evolution/drop-table/model.hxx | 51 |
1 files changed, 47 insertions, 4 deletions
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<int> 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 } |