Project

General

Profile

Feature #3400

Wt::Dbo::field() with prefix

Added by Saif Rehman over 8 years ago. Updated almost 7 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
Target version:
Start date:
06/29/2014
Due date:
% Done:

0%

Estimated time:

Description

In the test file, there is a case where there can't be more than 1 fields that represent a Dbo's ID if that Dbo is using a composite key. The test file include 2 Dbos:

  1. Module - Uses default surrogate key
  2. Page - Uses composite key of type 'long long' and 'Wt::Dbo::ptr'

Page Dbo also has a ManyToOne relation with Page Dbo itself, representing parent and children pages. Creating tables fails because, there is a duplicate Page_id and Module_id. I tried concatenating the field() arguments, however, it only causes relation with Module to break. I couldn't include the case with concatenated field()s, I will upload that too as soon as my computer is ready.

I suggest that to solve this problem, Wt::Dbo::field should have an extra argument for adding prefix to the field name.


Files

DboTestCompositeKey.C (3.54 KB) DboTestCompositeKey.C Saif Rehman, 06/29/2014 10:15 PM
DboTestCompositeKey.C (3.6 KB) DboTestCompositeKey.C Saif Rehman, 01/07/2016 07:50 PM
#1

Updated by Koen Deforche about 8 years ago

  • Status changed from New to InProgress
  • Assignee set to Koen Deforche
  • Target version set to 3.3.4
#2

Updated by Koen Deforche about 8 years ago

  • Status changed from InProgress to Feedback

Hey,

You're supposed to use the 'name' then to concatenate with the composite field id's.

See for example:

//Mapping for PageKeys composite key
namespace Wt
{
    namespace Dbo
    {
        template<class Action>
        void field(Action &action, PageKeys &Keys, const std::string &name, int size = -1)
        {
            field(action, Keys.id, name + "_page_id");
            belongsTo(action, Keys.ModulePtr, name + "_Module", Wt::Dbo::OnDeleteCascade | Wt::Dbo::OnUpdateCascade | Wt::Dbo::NotNull);
        }
    }
}
#3

Updated by Saif Rehman about 8 years ago

I've tried that. Did not work because the name in hasMany() and name in belongsTo() has to be the same. I've failed on this method and couldn't get it to work for quite a long time.

#4

Updated by Saif Rehman about 8 years ago

Database error creating tables: Relation mismatch for table 'modules': no matching belongsTo() found in table 'pages' with name 'Module', but did find with name 'Page_Module'?

Throws once

#5

Updated by Koen Deforche about 8 years ago

Hey,

I added this exact code as a test case (DboTestCompositeKey.C) in git, and it's working?

Koen

#6

Updated by Saif Rehman about 8 years ago

Yea ... It throws only once for some reason... It is caught when an attempt to drop tables is made. If you try any other operation it throws weird stl library related exceptions.

Remove the lines starting from line 150

//Drop/Create
                try
                {
                        session_->dropTables(); //todo:remove
                }
                catch(...)
                { }
#7

Updated by Saif Rehman almost 7 years ago

Here is the update version of the test case, the previous test case was suppressing the error somehow.

Also available in: Atom PDF