progress on relation completer
This commit is contained in:
+1
-2
@@ -18,7 +18,6 @@ struct author {
|
||||
bool distinguished{false};
|
||||
matador::object::collection<matador::object::object_ptr<book>> books;
|
||||
|
||||
|
||||
template<typename Operator>
|
||||
void process( Operator& op ) {
|
||||
namespace field = matador::access;
|
||||
@@ -28,7 +27,7 @@ struct author {
|
||||
field::attribute( op, "date_of_birth", date_of_birth, 31 );
|
||||
field::attribute( op, "year_of_birth", year_of_birth );
|
||||
field::attribute( op, "distinguished", distinguished );
|
||||
field::has_many( op, "books", books, "author_id" );
|
||||
field::has_many( op, "books", books, "author_id", matador::utils::default_foreign_attributes );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ struct book {
|
||||
namespace field = matador::access;
|
||||
field::primary_key( op, "id", id );
|
||||
field::attribute( op, "title", title, 511 );
|
||||
field::has_one( op, "author_id", book_author, matador::utils::default_foreign_attributes );
|
||||
field::belongs_to( op, "author_id", book_author, matador::utils::default_foreign_attributes );
|
||||
field::attribute( op, "published_in", published_in );
|
||||
}
|
||||
};
|
||||
|
||||
+42
-1
@@ -5,6 +5,48 @@
|
||||
#include "author.hpp"
|
||||
#include "book.hpp"
|
||||
|
||||
|
||||
/*
|
||||
* node author
|
||||
*
|
||||
* relation_endpoints
|
||||
* 1. - field_name "books"
|
||||
* - type_index <book>
|
||||
* - type "has_many"
|
||||
* - node <author>
|
||||
* - foreign endpoint (1) "author"
|
||||
*
|
||||
* node book
|
||||
* 2. - field_name "author_id"
|
||||
* - type_index <author>
|
||||
* - type "belongs_to"
|
||||
* - node <book>
|
||||
* - foreign endpoint (2) "books"
|
||||
*
|
||||
* Attach process:
|
||||
*
|
||||
* attach<author>
|
||||
* - relation completer detects "has_many<book>"
|
||||
* - has_many<book> doesn't find <book> (not yet attached)
|
||||
* - create endpoint (1) without foreign endpoint
|
||||
* - create node many_to_many_relation<author, book>("author_id", "id")
|
||||
* - 3. create endpoint
|
||||
* - field name "author_id"
|
||||
* - type_index <author>
|
||||
* - type "belongs_to"
|
||||
* - node <many_to_many_relation<author, book>>
|
||||
* - foreign endpoint (1) "author
|
||||
* - set foreign endpoint of (1) to endpoint (3)
|
||||
* - attach (internal) node<many_to_many_relation<author, book>>
|
||||
*
|
||||
* attach<book>
|
||||
* - relation completer detects "belongs_to<author>"
|
||||
* - belongs_to<author> finds <book>
|
||||
* - check relation endpoints...
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
using namespace demo;
|
||||
using namespace matador;
|
||||
int main() {
|
||||
@@ -15,5 +57,4 @@ int main() {
|
||||
|
||||
auto result = schema.attach<author>("authors")
|
||||
.and_then([&schema] { return schema.attach<book>("books"); });
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user