added belongs to and has one tests

This commit is contained in:
2026-05-13 16:09:35 +02:00
parent e3618c60e3
commit 1cdd83cb31
8 changed files with 275 additions and 81 deletions
-51
View File
@@ -15,56 +15,6 @@ using namespace matador::object;
using namespace matador::test;
namespace matador::test {
template<const utils::primary_key_attribute &PkAttribute>
struct book_pk_generator;
template<const utils::primary_key_attribute &PkAttribute>
struct author_pk_generator {
unsigned int id{};
std::string name;
collection<object_ptr<book_pk_generator<PkAttribute>>> books;
author_pk_generator() = default;
explicit author_pk_generator(std::string name)
: name(std::move(name)) {}
template<typename Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id, PkAttribute);
field::attribute(op, "name", name, VarChar63);
field::has_many(op, "books", books, "author_id", utils::CascadeAllFetchLazy);
}
};
template<const utils::primary_key_attribute &PkAttribute>
struct book_pk_generator {
unsigned int id{};
std::string title;
object_ptr<author_pk_generator<PkAttribute>> book_author;
unsigned short published_in{};
book_pk_generator() = default;
book_pk_generator(std::string title, object_ptr<author_pk_generator<PkAttribute>> author, const unsigned short published_in)
: title(std::move(title)), book_author(std::move(author)), published_in(published_in) {}
template<typename Operator>
void process(Operator &op) {
namespace field = matador::access;
field::primary_key(op, "id", id, PkAttribute);
field::attribute(op, "title", title, VarChar511);
field::belongs_to(op, "author_id", book_author, utils::CascadeAllFetchEager);
field::attribute(op, "published_in", published_in);
}
};
using author_identity = author_pk_generator<utils::Identity>;
using author_sequence = author_pk_generator<utils::Sequence>;
using author_table = author_pk_generator<utils::Table>;
using book_identity = book_pk_generator<utils::Identity>;
using book_sequence = book_pk_generator<utils::Sequence>;
using book_table = book_pk_generator<utils::Table>;
template<const utils::primary_key_attribute &PkAttribute>
struct colorlist_pk_generator {
unsigned int id{};
@@ -88,7 +38,6 @@ struct colorlist_pk_generator {
using colorlist_identity = colorlist_pk_generator<utils::Identity>;
using colorlist_sequence = colorlist_pk_generator<utils::Sequence>;
using colorlist_table = colorlist_pk_generator<utils::Table>;
}
template<typename AuthorType, typename BookType>