[odb-users] Lazy Relationships?

Boris Kolpackov boris at codesynthesis.com
Wed Sep 23 12:20:54 EDT 2015


Hi Christian,

Christian Sell <christian at gsvitec.com> writes:

> yes, and in fact, I mentioned sections as the only way I had found to achieve
> "full lazyness". However, this is not feasible because, as I said, I am mapping
> classes that I cannot modify. Therefore my question was if I could achieve the
> same with custom relationship (container) and accompanying container_traits

ODB needs a place to store the state of the section somewhere (is it
loaded? etc). What you could try to do is hide the section data member
inside the container. Here is an outline:

#include <odb/section.hxx>

template <typename T>
struct sectioned_vector
{
  odb::section s;
};

#pragma db object
struct object
{
  #pragma db id
  int id;

  #pragma db member(s) virtual(odb::section) load(lazy) access(v.s)

  #pragma db section(s)
  sectioned_vector<int> v;
};

Kind of cool, actually.

Boris



More information about the odb-users mailing list