<?xml version="1.0"?> <!DOCTYPE database SYSTEM "http://litesql.sourceforge.net/litesql.dtd"> <database name="TestDatabase" namespace="test"> <object name="Person"> <field name="name" type="string"/> </object> <relation name="FriendsRelation"> <relate object="Person" handle="friends"/> <relate object="Person"/> </relation> </database>
Methods:
RelationHandle-class' methods:
Person bill(db), bob(db); bill.name = "Bill"; bill.update(); bob.name = "Bob"; bob.update(); // both objects must be stored in database before they can be linked bill.friends().link(bob); // following statement would throw an exception because they are already friends // (friends is bidirectional relation) bob.friends().link(bill);
A fetching example:
Person bob = bill.friends().get(Person::Name == "Bob").one();
vector<Person> billsFriends = bill.friends().get().all();
An unlinking example:
// Bill and Bob are no longer friends
bill.friends().unlink(bob);
A linking example:
Person bill(db), bob(db); bill.name = "Bill"; bill.update(); bob.name = "Bob"; bob.update(); // both objects must be stored in database before they can be linked FriendsRelation::link(db, bill, bob);
A fetching example:
Person bob = FriendsRelation::getPerson2(db,
Person::Name == "Bob",
FriendsRelation::Person1==bill.id).one();
vector<Person> billsFriends =
FriendsRelation::getPerson2(db, Expr(),
FriendsRelation::Person1==bill.id).all();
An unlinking example:
// Bill and Bob are no longer friends
Friendsrelation::unlink(bill, bob);