Project

General

Profile

Actions

Bug #6076

open

[Wt::Dbo] How to work with entities without parameter-less constructors (classes that require an invariant)

Added by Oleg Artenii over 6 years ago. Updated over 6 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
10/30/2017
Due date:
% Done:

0%

Estimated time:

Description

I have a class with an explicit constructor that requires two parameters, without those parameters the instance is invalid. When I try to map it with Wt it requires a default parameter-less constructor (I think just to create an instance to be able to execute the persist() method).

Is there any way to make Wt to not construct an object but still be able to extract the mapping data for object?

As a quick fix I created a parameter-less constructor and initialize the required members with nullptr but this can cause troubles in future.

Actions #1

Updated by Wim Dumon over 6 years ago

You're correct that Wt::Dbo has to be able to create an instance of your object when it is retrieved from the database. It uses the default constructor for that, and fills out the data fields according to the values stored in the database.

Alternatively, we should add a method to the traits class to create an object of a specific type.

Wim.

Actions #2

Updated by Oleg Artenii over 6 years ago

Alternatively, we should add a method to the traits class to create an object of a specific type.

If in that method I will be able to create the dependent objects first (which are part of invariant) then pass them to constructor, then it's a good solution.

Actions

Also available in: Atom PDF