[odb-users] Composing object view attribute

Roman Shametko shametko.roman at gmail.com
Tue Apr 14 11:36:43 EDT 2015


Hi. Thank you for your answer.

Post load is not seems to be what I am looking for.
Let me explain it. Have a look at class

class AdjacencyListItem {
public:
     std::shared_ptr<AdjacencyListItem> m_parent;
     std::string m_nodeName;

     std::string nodePath() {...}
};

It contains list of parent nodes. Assume we have object A of 
AdjacencyListItem type. This object contains following: 
A->m_parent/*"Documents"*/->m_parent/*"username"*/->m_parent/*"home"*/->m_parent/*"/"*/. 


Adjacency list item can return it's path by getting all it's parents 
names recursively. So I can call A->m_parent->getPath() which gonna 
result in "/home/username/Documents/". This is the path I want to get in 
view. But I don't really understand how can I achieve this. Basically 
I'd be happy with following view:

#pragma db view /*some other objects*/  object(AdjacencyListItem)
class View {
public:
     ...
      std::shared_ptr<AdjacencyListItem> m_parent;
};

But as far as I understand it's impossible to get one.

Thanks in advance.

On 04/13/2015 05:11 PM, Boris Kolpackov wrote:
> Hi Roman,
>
> Roman Shametko <shametko.roman at gmail.com> writes:
>
>> So my question is: Is there any way to supply Views with manually
>> composed values?
> Normally a view gets values for its members from the database
> (query). But you can also declare a member transient and compute
> its value using a database operation callback (e.g., post_load;
> Section 14.2.5).
>
> Not sure if this is what you are looking for. If not, then
> describe how you see the m_nodePath calculation being
> implemented under the hood.
>
> Boris



More information about the odb-users mailing list