[odb-users] How to use the lazy_weak_ptr?

黄奕 ruffian_hy at 126.com
Sat Nov 16 00:30:08 EST 2019


I found that I can not use inverse in our project, 
But if I remove  “#pragma db inverse(m_b)”, all the function below will get a nullptr
if(m_a.loaded())
auto post = m_a.get_eager().lock();
        auto post1=m_a.get_eager();
        auto post2 = m_a.load();
        auto post3 = m_a.lock();
        auto post4 = post3.load();
        auto post5 = post3.get_eager();
}


How can I get the object from lazy_weak_ptr?


At 2019-11-16 02:52:50, "Boris Kolpackov" <boris at codesynthesis.com> wrote:
>黄奕 <ruffian_hy at 126.com> writes:
>
>> class B
>> {
>> ...
>> private:
>> #pragma db inverse(m_b)
>> 
>> odb::lazy_weak_ptr<A> m_a;
>> ...
>> };
>> #pragma db object(B) pointer(std::shared_ptr)
>> #pragma db member(m_a)
>>  
>> But I get the error of “error: object data member ‘ m_a' specified in db pragma column is inverse”.
>
>Try to move inverse to the member(m_a) pragma:
>
>#pragma db member(m_a) inverse(m_b)
>
>Also, dealing with circular relationship is tricky, especially when
>spread over multiple headers; see "Circular Relationships" in the
>manual for details:
>
>https://codesynthesis.com/products/odb/doc/manual.xhtml#6.3


More information about the odb-users mailing list