#include "matador/object/schema.hpp" #include "matador/logger/log_manager.hpp" #include "author.hpp" #include "book.hpp" #include /* * node author * * relation_endpoints * 1. - field_name "books" * - type "has_many" * - node * - foreign endpoint (1) "author" * * node book * 2. - field_name "author_id" * - type "belongs_to" * - node * - foreign endpoint (2) "books" * * Attach process: * * attach * - relation completer detects "has_many" * - has_many doesn't find (not yet attached) * - create endpoint (1) without foreign endpoint * - create node many_to_many_relation("author_id", "id") * - 3. create endpoint * - field name "author_id" * - type "belongs_to" * - node > * - foreign endpoint (1) "author * - set foreign endpoint of (1) to endpoint (3) * - register endpoint in authors node by type book * - attach (internal) node> * * attach * - relation completer detects "belongs_to" * - belongs_to finds * - try to find relation endpoint of type book in authors node * - if endpoint was found * - validate node in endpoint * - if node is of type many_to_many_relation * - detach node of endpoint * - update node in endpoint to * - else * - create endpoint (1) * - create endpoint (2) * - set foreign endpoint of (1) to endpoint (2) * - set foreign endpoint of (2) to endpoint (1) * - check relation endpoints... */ using namespace demo; using namespace matador; int main() { logger::default_min_log_level(logger::log_level::LVL_DEBUG); logger::add_log_sink(logger::create_stdout_sink()); { object::schema schema; auto result = schema.attach("authors") .and_then([&schema] { return schema.attach("books"); }); schema.dump(std::cout); } { object::schema schema; auto result = schema.attach("books") .and_then([&schema] { return schema.attach("authors"); }); schema.dump(std::cout); } }