[odb-users] Usage of lazy shared pointers in a triangle relation

Boris Kolpackov boris at codesynthesis.com
Thu Oct 23 01:34:14 EDT 2014


Hi Quentin,

Quentin Deldycke <quentindeldycke at gmail.com> writes:

> I have a problem using this kind of architecture:
> 
> - class A have a lazy_shared_pointer to C
> - class B have a lazy_shared_pointer to another C
> - class C contains a int
> 
> In my mysql database, we can easily see that our class A
> is linked to a class C with value '1' and my class 'B' is linked
> to a class C with value '2'.
> 
> In my code, I query all class A, for each A, we query for objects B.
> For each B I print values of A, B and the class C of both of them.

I am not sure what "for each A, we query for objects B" means since
from your description above they seem to be unrelated.


> Strangely, I have only output of C == '2'.
> 
> I then tried to compare the pointer of both C object stored in A and B.
> I found that they are the same! So for each loop on objects B, the value of
> A->C is updated to values of B->C.

I can't think of any reason why this would happen other than if both C's
had the same primary key. So I would need to see the actual code that
does the query. Actual class declarations could also be helpful. What
happens if you print the value of A-C before you "query for objects B"?


> Do you have any int to avoid this problem?

int64_t helps with all kinds of problems ;-)

Boris



More information about the odb-users mailing list