c++postgresqlodb

C++ and ODB: Creating a vector of objects


I have an object called TimelineItem which has a datafield called linked_items_ which holds a vector of type TimelineItem. This is to represent items in a timeline that are linked to the original item (repeated items).

I'm having a hard time getting ODB to understand my intent. It is giving me an error "unable to map C++ type "::TimelineItem" used in data member 'linked_items_' to a PostgreSQL database type. Here is my code:

#pragma db object
class TimelineItem {

    // Timeline Item data fields
    private:
        // Default constructor for ODB
        TimelineItem() {}

        friend class odb::access;

        #pragma db id auto
        unsigned long id_;

        Event *event_;
        time_t start_;
        time_t end_;
        TimelineItem *linked_;
        vector<TimelineItem> linked_items_;

I get that it doesn't know what type "TimelineItem" is so it can't map it on the database side, however I'm struggling to find documentation or a way to fix this.

Any feedback is appreciated.

Thanks!


Solution

  • I think your vector<TimelineItem> linked_items_; should actually be vector<TimelineItem*> linked_items_;