[odb-users] Pointer as a member of Class
nima chavooshi
nima0102 at gmail.com
Tue Sep 16 01:14:50 EDT 2014
Hi Boris,
Thanks a lot for your attention. I think I could not explain what I expect.
Please kindly see my classes:
////////////////////////////////Person/////////////////
#pragma db object
class Person
{
private:
#pragma db id auto
unsigned long id_;
int Age;
string FirstName;
string LastName;
Contact * ContactPerson;
public:
friend class odb::access;
Person(int AgeNumber,string FName,string LName,string Addr,string
PhoneNum);
~Person();
void Get();
};
/////////////////////////////Person////////////////////////
////////////////////////////Contact/////////////////////////
#pragma db object
class Contact
{
private:
friend class odb::access;
public:
#pragma db id auto
unsigned long id_;
string Address;
string PhoneNumber;
Contact(string Addr,string PhoneNum);
const char * GetAddr();
const char * GetPhone();
};
/////////////////////////Contact/////////////////////////
And also I doubt about generated schema, because there is no any
"REFERENCE" keyword in schema then there is no defined relationship between
2 tables.
On Mon, Sep 15, 2014 at 6:32 PM, Boris Kolpackov <boris at codesynthesis.com>
wrote:
> Hi Nima,
>
> nima chavooshi <nima0102 at gmail.com> writes:
>
> > In my test program, I created a class that contains a pointer to another
> > class as a member. I compiled with odb and imported related schema to DB
> > and compile my main program. The pointer member is not inserted correctly
> > to associated table on DB and just inserted a big number in DB and the
> > table of another class is not inserted any data!!
>
> What you are probably expecting is for ODB to automatically persist the
> pointed-to object (AKA cascading persist). ODB doesn't do that. With
> ODB we tried to stick to the "one ORM operation translates to one
> database operation" design as closely as possible.
>
> So what you need to do to make this work is to first persist the
> pointed-to object and then the objected itself. Something along
> these lines:
>
> person p = ...
>
> db.persist (p->contact);
> db.persists (p);
>
>
> > If ODB supports a pointer as a member and could map it to db data
> > type, please kindly guide me.
>
> All this is discussed in the relevant parts of the ODB manual.
>
> Boris
>
More information about the odb-users
mailing list