fnc12/sqlite_orm

Cannot bind with getters and setters when inherited

vahagnIV opened this issue · 4 comments

Hi,

I am writing a program that depends on this library. I have many classes that I store and retrieve from the database.

I am trying to minimize my code as follows

I have

class Base {
  int id_:
  
  public:
    void SetId(int id) {
      id_ = id;
    }

    int GetId() const {
      return id_;
    }

};

And many classes

class Child: public A { // also Child1, Child2...
  // B specific things here
};

Now when I want to create a table for Child

make_table("Child",
            make_column("id", &Child::SetId, &Child::GetId, primary_key())
      // ....
);

and this fails to compile.
I understand that this has something to do with the deduction of the table from the getter/setter's type, but still is there a workaround?

You can and must specify the table part explicitly when you create a table and later when you refer to the columns.

In a nutshell: make_table<Child>(...) and column<Child>(&Child::GetId).
See answer to the same question.

fnc12 commented

@vahagnIV did it work?

fnc12 commented

I bet it will work. If it won't please feel free to reopen the issue

Yes, it worked. Thank you very much.
Sorry for not coming back. I simply forgot to respond.