Project

General

Profile

Wt::Dbo: Possible to Implement some inheritance-awareness through tricky chaining function?

Added by Jörn M almost 8 years ago

Hi Folks!

I'm currently pondering to find some solution to implement some inheritance-awareness for easier implementation of plugin/addons to existing dbo-classes. As far as I have seen, information about the mapping (fields and table) is passed along in the Action which visits persist(). I'm just toe-deep into the inner workings of Wt::Dbo, so I do not know how and when the query is constructed and if following trick could work:

I wonder if it would be possible to implement at least some handling for class-inheritance by introducing a template function inherit(...) which retrives mapping of the parent-type from the session, fires up another remapped action and passes it along to the parents persist(...) member function.

Something:


namespace dbo

{

template <class Parent, class Action, class Child>

void inherit(Action& a, Child* c)

{

Parent* p = dynamic_cast<Parent*>©;

/* Do some magic here to retrieve mapping and create an Action aParent */

p->persist(aParent);

}

}

class A

{

protect:

std::string str;

public:

persist(Action& a)

{

dbo::field(a, str, "str");

}

}

class B : public A

{

protected:

int number;

public:

template

persist(Action& a)

{

dbo::field(a, number, "number");

dbo::inherit(a, this); //

}

}


I believe I'll need to at least change some code of Wt::Dbo in my repo as all possibilities to get a Hand on a Mapping for Parent are private. Question is will it be possible without rewriting to much code and if so, where would be the best point to get start.

Cheers

Jörn