[odb-users] PKs and FKs at the same time
Nicholas Cremonesi
nicholas.cremonesi at gmail.com
Fri Mar 20 11:31:49 EDT 2015
Hello Boris,
I tried to define the callback as in the example you gave me, but I
encountered some troubles.
This is my code:
==========
class Table_A
{
private:
...
#pragma db id
int pk_tblA_;
#pragma db transient
shared_ptr<Table_B> FK_TableA_TableB_;
void init (odb::callback_event e, odb::database& db)
{
if (e == odb::callback_event::post_load)
FK_TableA_TableB_ = db.load<Table_B> (pk_tblA_);
}
};
==========
And this is the error odb compiler returns to me:
>> odb -d sqlite --generate-query --generate-schema --generate-session *.hxx
>> cannot convert ‘((Table_A*)this)->Table_A::pk_tblA_’ (type ‘int’) to
type ‘const odb::access::object_traits<Table_B>::id_type&’
FK_TableA_TableB_ = db.load<Table_B> (pk_tblA_);
2015-03-20 13:56 GMT+01:00 Nicholas Cremonesi <nicholas.cremonesi at gmail.com>
:
> Thanks Boris,
>
> I'm going to read carefully the documentation about callbacks.
> My question is, how can I perform queries once defined the callbacks?
>
> 2015-03-20 12:30 GMT+01:00 Boris Kolpackov <boris at codesynthesis.com>:
>
>> Hi Nicholas,
>>
>> Nicholas Cremonesi <nicholas.cremonesi at gmail.com> writes:
>>
>> > I have to define a column (let's call it 'col_B') which is both Primary
>> Key
>> > of 'Class_B' and Foreign Key referencing 'Class_A', so I tried to
>> define it
>> > this way:
>> >
>> > #pragma db id
>> > shared_ptr<Class_A> col_B_;
>> >
>> > but compiling with ODB give me a lot of errors. Is this implementation
>> > unable to do?
>>
>> No, ODB does not support using object pointers as object ids. However,
>> you can quite easily emulate this behavior as described in this earlier
>> post:
>>
>> http://www.codesynthesis.com/pipermail/odb-users/2015-January/002335.html
>>
>> Boris
>>
>
>
More information about the odb-users
mailing list