diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-11-17 18:05:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-11-17 18:05:06 +0200 |
commit | 2fe7a723c0b98d23531a76d9c1a451e3a57bf0c5 (patch) | |
tree | 8bd0323a9114a405902b3dfc116f97307278ae2b /odb/mysql/schema.cxx | |
parent | 302b804ec633889f26dc54d937d9becc09246152 (diff) |
Add support for unidirectional object relationships
New test: common/relationship.
Diffstat (limited to 'odb/mysql/schema.cxx')
-rw-r--r-- | odb/mysql/schema.cxx | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/odb/mysql/schema.cxx b/odb/mysql/schema.cxx index 1dfeb1f..0c004ad 100644 --- a/odb/mysql/schema.cxx +++ b/odb/mysql/schema.cxx @@ -18,8 +18,8 @@ namespace mysql struct object_columns: object_columns_base, context { - object_columns (context& c) - : object_columns_base (c), context (c) + object_columns (context& c, string const& prefix = string ()) + : object_columns_base (c), context (c), prefix_ (prefix) { } @@ -29,11 +29,21 @@ namespace mysql if (!first) os << "," << endl; - os << " `" << name << "` " << column_type (m); + os << " `" << name << "` " << column_type (m, prefix_); if (m.count ("id")) os << " PRIMARY KEY"; + + using semantics::class_; + if (class_* c = object_pointer (m, prefix_)) + { + os << " REFERENCES `" << table_name (*c) << "` (`" << + column_name (id_member (*c)) << "`)"; + } } + + private: + string prefix_; }; struct member_create: object_members_base, context @@ -67,7 +77,7 @@ namespace mysql // object_id (simple value) // string id_name (column_name (m, "id", "object_id")); - os << " `" << id_name << "` " << column_type (id_member_); + os << " `" << id_name << "` " << column_type (id_member_, "ref"); // index (simple value) // @@ -95,8 +105,9 @@ namespace mysql } else { + object_columns oc (*this, "key"); string const& name (column_name (m, "key", "key")); - os << " `" << name << "` " << column_type (m, "key"); + oc.column (m, name, true); } } @@ -112,8 +123,9 @@ namespace mysql } else { + object_columns oc (*this, "value"); string const& name (column_name (m, "value", "value")); - os << " `" << name << "` " << column_type (m, "value"); + oc.column (m, name, true); } } |