[odb-users] FOREIGN KEY is commented (one-to-many)
Mohammad Pahlevan
pahlevan at gmail.com
Wed Jul 22 07:08:44 EDT 2015
Dear Sir,
in SQL Script that Generated by odb compiler, FOREIGN KEY for one-to-many
Relation is Commented.
Who can I enable this relation?
-------------------------------------------------------------
-- odb command
odb -d mssql --generate-query --generate-schema employee.hxx
--------------------------------------------------------------
-- sql generated
/* This file was generated by ODB, object-relational mapping (ORM)
* compiler for C++.
*/
IF OBJECT_ID('employee', 'U') IS NOT NULL
DROP TABLE [employee];
GO
IF OBJECT_ID('employer', 'U') IS NOT NULL
DROP TABLE [employer];
GO
CREATE TABLE [employer] (
[id] INT NOT NULL PRIMARY KEY IDENTITY,
[val1] INT NOT NULL,
[val2] INT NOT NULL,
[val3] INT NOT NULL,
[val4] INT NOT NULL);
GO
CREATE TABLE [employee] (
[id] INT NOT NULL PRIMARY KEY,
[name1] VARCHAR(512) NOT NULL,
[name2] VARCHAR(512) NOT NULL,
[employer] INT NOT NULL
/*
CONSTRAINT [employee_employer_fk]
FOREIGN KEY ([employer])
REFERENCES [employer] ([id])
*/);
GO
------------------------------------------------------------------------------------------------------
-- employee.hxx file
#ifndef EMPLOYEE_HXX
#define EMPLOYEE_HXX
#include <vector>
#include <string>
#include <odb/core.hxx>
#include <odb/tr1/memory.hxx>
using std::tr1::shared_ptr;
using std::tr1::weak_ptr;
class employee;
#pragma db object
class employer
{
private:
friend class odb::access;
employer () {}
#pragma db id auto
int id_;
int val1_;
int val2_;
int val3_;
int val4_;
#pragma db not_null inverse(employer_)
std::vector<weak_ptr<employee> > employees_;
};
#pragma db object
class employee
{
public:
employee ();
employee (const std::string&);
private:
friend class odb::access;
#pragma db id
int id_;
std::string name1_;
std::string name2_;
#pragma db not_null
shared_ptr<employer> employer_;
};
#endif // EMPLOYEE_HXX
TNX
More information about the odb-users
mailing list