Project

General

Profile

Bug #3577 » mainNonReflexive.cpp

Anonymous, 09/11/2014 05:57 PM

 
1
#include<iostream>
2
#include<Wt/Dbo/Dbo>
3
#include<Wt/Dbo/backend/Sqlite3>
4

    
5

    
6
class testClass;
7
class testClass2;
8

    
9
class testClass
10
{
11
public:
12
	std::string name;
13
	
14
	Wt::Dbo::collection<Wt::Dbo::ptr<testClass2> >testRelation;
15
	
16
	template<class Action>
17
	void persist(Action&a)
18
	{
19
		Wt::Dbo::field(a,name,"name");
20
		
21
		Wt::Dbo::hasMany(a,testRelation,Wt::Dbo::ManyToMany,"testRelation");
22
	}
23
};
24

    
25
class testClass2
26
{
27
public:
28
	std::string name;
29
	
30
	Wt::Dbo::collection<Wt::Dbo::ptr<testClass> >testRelation;
31
	
32
	template<class Action>
33
	void persist(Action&a)
34
	{
35
		Wt::Dbo::field(a,name,"name");
36
		
37
		Wt::Dbo::hasMany(a,testRelation,Wt::Dbo::ManyToMany,"testRelation");
38
	}
39
};
40

    
41

    
42
int main(int argc,char**argv)
43
{
44
	Wt::Dbo::backend::Sqlite3 dbBackend(":memory:");
45
	Wt::Dbo::Session dbSession;
46
	Wt::Dbo::ptr<testClass>ptr1;
47
	Wt::Dbo::ptr<testClass2>ptr2;
48
	
49
	dbSession.setConnection(dbBackend);
50
	dbSession.mapClass<testClass>("testClass");
51
	dbSession.mapClass<testClass2>("testClass2");
52
	dbSession.createTables();
53
	
54
	
55
	Wt::Dbo::Transaction tr(dbSession);
56
	ptr1=dbSession.add(new testClass);
57
	ptr2=dbSession.add(new testClass2);
58
	
59
	ptr1.modify()->name=std::string("object1");
60
	ptr2.modify()->name=std::string("object2");
61
	
62
	ptr1.modify()->testRelation.insert(ptr2);
63
	
64
	dbSession.flush();
65

    
66
	ptr1.modify()->testRelation.clear();
67
	
68
	dbSession.flush();
69
	
70
	return 0;
71
}
(2-2/2)