From a93ad74833e3a99a1421fd695a01a1fb15d1f2dd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 25 Apr 2012 09:04:35 +0200 Subject: Fix auto id handling in polymorphic objects --- common/polymorphism/driver.cxx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'common/polymorphism/driver.cxx') diff --git a/common/polymorphism/driver.cxx b/common/polymorphism/driver.cxx index efda095..0c9bf1e 100644 --- a/common/polymorphism/driver.cxx +++ b/common/polymorphism/driver.cxx @@ -1821,6 +1821,38 @@ main (int argc, char* argv[]) t.commit (); } } + + // Test 12: polymorphic objects with auto id. + // + { + using namespace test12; + + base b (1); + derived d (2); + + unsigned long id1, id2; + + // Persist. + // + { + transaction t (db->begin ()); + id1 = db->persist (b); + id2 = db->persist (static_cast (d)); + t.commit (); + } + + // Load. + // + { + transaction t (db->begin ()); + auto_ptr pb (db->load (id1)); + auto_ptr pd (db->load (id2)); + t.commit (); + + assert (*pb == b); + assert (*pd == d); + } + } } catch (const odb::exception& e) { -- cgit v1.1