[odb-users] Testing whether lazy_shared_ptr is null

Brian Coggins becoggins at hotmail.com
Sat Apr 20 12:20:58 EDT 2019


Imagine I have two types of object A and B with a unidirectional A to B relationship.  If I load an object A containing a lazy_shared_ptr< B >, what is the best way to determine whether this lazy_shared_ptr< B > represents a relationship to an instance of B (of any kind, transient or persistent, loaded or unloaded), or if it is null?

>From reading the docs, I think I could call lazy_shared_ptr< B >::load() and then test whether the returned shared_ptr< B > is nullptr.  However, if lazy_shared_ptr< B > points to a B, this has the side effect of loading the instance of B, and I don’t actually need the B.  I just need to know whether A has a relationship to B.  It seems like there must be a way to check this without loading the pointed-to object?

Of course, at the database level one could query for whether the field in A representing the relationship is NULL, but I was hoping to find a way to get this info from the C++ object.

Thanks,
Brian






More information about the odb-users mailing list