Project

General

Profile

Bug #3577 » main.cpp

Anonymous, 09/11/2014 05:57 PM

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

    
4

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

    
23

    
24
int main(int argc,char**argv)
25
{
26
	Wt::Dbo::backend::Sqlite3 dbBackend(":memory:");
27
	Wt::Dbo::Session dbSession;
28
	Wt::Dbo::ptr<testClass>ptr1;
29
	Wt::Dbo::ptr<testClass>ptr2;
30
	
31
	dbSession.setConnection(dbBackend);
32
	dbSession.mapClass<testClass>("testClass");
33
	dbSession.createTables();
34
	
35
	
36
	Wt::Dbo::Transaction tr(dbSession);
37
	ptr1=dbSession.add(new testClass);
38
	ptr2=dbSession.add(new testClass);
39
	
40
	ptr1.modify()->name=std::string("object1");
41
	ptr2.modify()->name=std::string("object2");
42
	
43
	ptr1.modify()->testRelationActive.insert(ptr2);
44
	
45
	dbSession.flush();
46
	
47
	ptr1.modify()->testRelationActive.clear();
48
	
49
	dbSession.flush();
50
	
51
	return 0;
52
}
(1-1/2)