Merge remote-tracking branch 'origin/feature/matador-ng' into feature/matador-ng
This commit is contained in:
@@ -20,7 +20,11 @@ namespace matador::object {
|
||||
// relation<OwnerType, ForeignType>
|
||||
|
||||
template < class RelationType >
|
||||
struct relation_iterator_traits;
|
||||
struct relation_iterator_traits {
|
||||
static RelationType& value(RelationType& item) {
|
||||
return item;
|
||||
}
|
||||
};
|
||||
|
||||
template < typename Type, typename OwnerType >
|
||||
struct relation_iterator_traits<relation<OwnerType, Type>> {
|
||||
@@ -39,11 +43,17 @@ public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
|
||||
collection_proxy_iterator() = default;
|
||||
explicit collection_proxy_iterator(typename std::vector<RelationType>::iterator it)
|
||||
collection_proxy_iterator(typename std::vector<RelationType>::iterator it)
|
||||
: it_(it) {}
|
||||
|
||||
reference operator*() { return *it_; }
|
||||
pointer operator->() { return &*it_; }
|
||||
reference operator*() {
|
||||
return relation_iterator_traits<relation_type>::value(*it_);
|
||||
}
|
||||
|
||||
pointer operator->() {
|
||||
return &relation_iterator_traits<relation_type>::value(*it_);
|
||||
}
|
||||
|
||||
collection_proxy_iterator& operator++() {
|
||||
++it_;
|
||||
return *this;
|
||||
@@ -55,9 +65,10 @@ public:
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
relation_type& relation() {
|
||||
return *it_;
|
||||
}
|
||||
// relation_type& relation() {
|
||||
|
||||
// return *it_;
|
||||
// }
|
||||
private:
|
||||
typename std::vector<RelationType>::iterator it_;
|
||||
};
|
||||
@@ -67,8 +78,10 @@ class abstract_collection_proxy {
|
||||
public:
|
||||
using value_type = Type;
|
||||
using relation_type = RelationType;
|
||||
using iterator = typename std::vector<value_type>::iterator;
|
||||
using const_iterator = typename std::vector<value_type>::const_iterator;
|
||||
// using iterator = typename std::vector<value_type>::iterator;
|
||||
// using const_iterator = typename std::vector<value_type>::const_iterator;
|
||||
using iterator = collection_proxy_iterator<value_type, relation_type>;
|
||||
using const_iterator = collection_proxy_iterator<value_type, relation_type>;
|
||||
|
||||
virtual ~abstract_collection_proxy() = default;
|
||||
|
||||
|
||||
@@ -3,5 +3,14 @@
|
||||
#include "matador/object/collection.hpp"
|
||||
#include "matador/object/object.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace matador::object;
|
||||
|
||||
TEST_CASE("Test collection", "[collection]") {
|
||||
collection<int> ints{{1,2,3,4}};
|
||||
|
||||
for (auto const& i : ints) {
|
||||
std::cout << i << std::endl ;
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ TEST_CASE_METHOD(QueryFixture, "Test delete builder has many to many", "[query][
|
||||
.and_then( [&scm] { return scm.attach<ingredient>("ingredients"); } );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
const std::vector ingredients {
|
||||
std::vector ingredients {
|
||||
make_object<ingredient>(1, "Apple"),
|
||||
make_object<ingredient>(2, "Strawberry"),
|
||||
make_object<ingredient>(3, "Pineapple"),
|
||||
@@ -82,12 +82,20 @@ TEST_CASE_METHOD(QueryFixture, "Test delete builder has many to many", "[query][
|
||||
make_object<ingredient>(7, "Beans")
|
||||
};
|
||||
|
||||
for (auto &i : ingredients) {
|
||||
i.change_state(object_state::Persistent);
|
||||
}
|
||||
|
||||
std::vector recipes {
|
||||
make_object<recipe>(1, "Apple Pie", std::vector{ingredients[0], ingredients[3], ingredients[4]}),
|
||||
make_object<recipe>(2, "Strawberry Cake", std::vector{ingredients[5], ingredients[6]}),
|
||||
make_object<recipe>(3, "Pineapple Pie", std::vector{ingredients[0], ingredients[1], ingredients[2]})
|
||||
};
|
||||
|
||||
for (auto &r : recipes) {
|
||||
r.change_state(object_state::Persistent);
|
||||
}
|
||||
|
||||
const auto contexts_by_type = to_contexts_by_name(scm, db->dialect());
|
||||
delete_query_builder<recipe> dqb(scm, contexts_by_type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user