[odb-users] Object reference in composite value type

Boris Kolpackov boris at codesynthesis.com
Mon Jan 27 23:18:39 EST 2014


Hi Harald,

Harald Frostel <Harald.Frostel at jku.at> writes:

> Is there a way to use a shared_ptr/lazy_shared_ptr in a composite
> value?

You can use object pointers in composite values. What you are looking
for is using object pointers in (composite) object ids. This is
currently not supported though we are planning to support this at
some point.

  
> The workaround right now is to use custom set/get methods (replace the
> reference in the composite value by an int parent_id_ and create a
> lazy_pointer of this parent id during loading) for the child object id
> but than, in the generate schema the foreign key relation is lost.

You could also go one step further and use a virtual data member
for parent_id (and a transient pointer member). This way you will
end up with a single physical data member (pointer) instead of two.
But yes, the foreign key semantics in the schema is lost with this
approach.


> Is there a way to solve this differently (without changing the schema
> of the database)?

The database schema that you are trying to re-create is very similar
to what one gets when using a container. So you may want to consider
making your child object actually a (composite) value and then have
a container of those in the parent object.

Boris



More information about the odb-users mailing list