[odb-users] Assign raw foreign key id without using a loaded object

Rene Jensen rene at catatonic.dk
Tue Sep 25 05:10:30 EDT 2012


On Tue, Sep 25, 2012 at 10:51 AM, Boris Kolpackov
<boris at codesynthesis.com>wrote:

> Hi Rene,
>
> Rene Jensen <rene at catatonic.dk> writes:
>
> > Say I have an object with a QLazyWeakPointer to some other class.
> > Can I assign a reference to a different id without having to load the
> > referred object into memory first, by simply using e.g. an integer key
> (if
> > my foreign key database type was INTEGER, of course):
> >
> > QSharedPointer<Format> F = ... load_format(10) ... bla bla
> >
> > P->format = 10;
> > P->format = F;
>
> Yes, you can initialize an unloaded lazy pointer with just an ID (and
> a reference to the database):
>
> P->format = QLazyWeakPointer<Format> (db, 10);
>
> This is discussed at the end of Section 6.4, "Lazy Pointers" in the
> ODB manual.
>


Indeed, it both works and is discussed in the manual. I am using ODB 2.0.0.
Thank you very much. This is an undispensable feature.

Regards,
Rene Jensen


More information about the odb-users mailing list