Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "join" requests resulting in mapped objects #19

Open
mfranck opened this issue Dec 7, 2012 · 0 comments
Open

Support for "join" requests resulting in mapped objects #19

mfranck opened this issue Dec 7, 2012 · 0 comments
Assignees

Comments

@mfranck
Copy link

mfranck commented Dec 7, 2012

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();
}

mfranck pushed a commit that referenced this issue Jan 16, 2013
* 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)
@ghost ghost assigned mfranck Jan 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant