You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Book : public table< Book > {
public:
TABLE_INIT(Book);
column< int > id;
column< std::string > title;
column< std::string > author;
reference< Person > owner;
COLLECTION(Person, borrowers);
};
TEST(TEST_JOIN, should_find_with_criteria_on_to_one) {
Person bob;
bob.id=12345;
Book of_bob_by_Tolkien;
of_bob_by_Tolkien.owner( bob );
of_bob_by_Tolkien.author.like( "Tolkien" );
collection < Book >Tolkiens_of_bob;
Tolkiens_of_bob=of_bob_by_Tolkien. find();
}
TEST(TEST_JOIN, should_find_with_criteria_on_to_manies) {
Book of_Tolkien;
of_Tolkien.author.like("Tolkien");
Person who_borrowed_tolkien;
who_borrowed_tolkien.borrowed_books ( of_Tolkien ) ; // A kind of tautology...
collection< Person > geeks;
geeks = who_borrowed_tolkien.find();
}
TEST(TEST_JOIN, should_traverse_several_to_manies) {
Person joe;
joe.name.like( "joe" );
Book read_by_joe;
read_by_joe.borrowers( joe ); // Mean : Joe is one of the borrowers.
Person fan_of_joe;
fan_of_joe.borrowed_books( read_by_joe );
collection< Person > fans_of_joe;
fans_of_joe = fan_of_joe.find() ;
}
* Accessors to "to-one" are now implemented in the owning class,
and removed from reference<T>, where they initially were implemented as "operator ()"
* Added macro for "to-one" member declaration
* Added macro for "to-one" accessors implementation (get/set).
=> all this stuff aims to prepare "join expressions" impl. (see issue #19)
class Person;
class Book : public table< Book > {
public:
TABLE_INIT(Book);
column< int > id;
column< std::string > title;
column< std::string > author;
reference< Person > owner;
COLLECTION(Person, borrowers);
};
has_and_belongs_to_many(Book,Person,borrowers,"borrows","borrowed_book_id", "borrower_id");
class Person : public table< Person > {
public:
TABLE_INIT(Person);
column< int > id;
column< std::string > name;
COLLECTION(Book, borrowed_books);
};
has_and_belongs_to_many(Person,Book,borrowed_books,"borrows","borrower_id","borrowed_book_id");
TEST(TEST_JOIN, should_find_with_criteria_on_to_one) {
Person bob;
bob.id=12345;
Book of_bob_by_Tolkien;
of_bob_by_Tolkien.owner( bob );
of_bob_by_Tolkien.author.like( "Tolkien" );
collection < Book >Tolkiens_of_bob;
Tolkiens_of_bob=of_bob_by_Tolkien. find();
}
TEST(TEST_JOIN, should_find_with_criteria_on_to_manies) {
Book of_Tolkien;
of_Tolkien.author.like("Tolkien");
Person who_borrowed_tolkien;
who_borrowed_tolkien.borrowed_books ( of_Tolkien ) ; // A kind of tautology...
collection< Person > geeks;
geeks = who_borrowed_tolkien.find();
}
TEST(TEST_JOIN, should_traverse_several_to_manies) {
Person joe;
joe.name.like( "joe" );
Book read_by_joe;
read_by_joe.borrowers( joe ); // Mean : Joe is one of the borrowers.
Person fan_of_joe;
fan_of_joe.borrowed_books( read_by_joe );
collection< Person > fans_of_joe;
fans_of_joe = fan_of_joe.find() ;
}
TEST(TEST_JOIN, should_traverse_several_to_manies_less_verbose) {
collection< Person > fans_of_joe;
fans_of_joe =Person().borrowed_books(Book().borrowers( Person().name.like("joe" ))).find();
}
The text was updated successfully, but these errors were encountered: