aboutsummaryrefslogtreecommitdiff
path: root/common/view/olv/test3.hxx
blob: 8cf4344308e2250673ad64df0c569adb8f9a0ae7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// file      : common/view/olv/test3.hxx
// license   : GNU GPL v2; see accompanying LICENSE file

#ifndef TEST3_HXX
#define TEST3_HXX

#include <string>
#include <vector>
#include <memory>  // shared_ptr

#include <odb/core.hxx>
#include <odb/lazy-ptr.hxx>

// Test JOINs for pointed-to objects, existing and automatically added.
//
#pragma db namespace table("t3_") pointer(std::shared_ptr) session
namespace test3
{
  using std::shared_ptr;

  struct object2;

  #pragma db object
  struct object1
  {
    object1 (int n_ = 0): n (n_) {}

    #pragma db id auto
    int id;

    int n;

    #pragma db inverse(o1)
    odb::lazy_weak_ptr<object2> o2;
  };

  #pragma db object
  struct object2
  {
    object2 (const char* s_ = ""): s (s_) {}

    #pragma db id auto
    int id;

    std::string s;

    shared_ptr<object1> o1;
  };

  #pragma db view object(object1) object(object2)
  struct view1a // Existing JOIN.
  {
    shared_ptr<object1> o1;
  };

  #pragma db view object(object1)
  struct view1b // Automatic JOIN.
  {
    shared_ptr<object1> o1;
  };

  // Container case.
  //
  struct object4;

  #pragma db object
  struct object3
  {
    object3 (int n_ = 0): n (n_) {}

    #pragma db id auto
    int id;

    int n;

    #pragma db inverse(o3)
    odb::lazy_weak_ptr<object4> o4;
  };

  #pragma db object
  struct object4
  {
    object4 (const char* s_ = ""): s (s_) {}

    #pragma db id auto
    int id;

    std::string s;

    std::vector<shared_ptr<object3>> o3;
  };

  #pragma db view object(object3) object(object4 = o4)
  struct view2a // Existing JOIN.
  {
    shared_ptr<object3> o3;
  };

  #pragma db view object(object3)
  struct view2b // Automatic JOIN.
  {
    shared_ptr<object3> o3;
  };
}

#endif // TEST3_HXX