diff --git a/README.md b/README.md index e61d90f8..32ffdae2 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,4 @@ See [INSTALL.md](INSTALL.md) file. ## Contributing -Contributions are welcome! Please prepare your pull requests on the [develop](../../tree/develop) branch. +Contributions are welcome! Please submit your pull requests against the [develop](../../tree/develop) branch. diff --git a/src/libs/database/impl/Cluster.cpp b/src/libs/database/impl/Cluster.cpp index 26dd4b21..0a3143c8 100644 --- a/src/libs/database/impl/Cluster.cpp +++ b/src/libs/database/impl/Cluster.cpp @@ -132,11 +132,25 @@ ClusterType::getAllOrphans(Session& session) { session.checkSharedLocked(); - Wt::Dbo::collection res = session.getDboSession().query>("select c_t from cluster_type c_t LEFT OUTER JOIN cluster c ON c_t.id = c.cluster_type_id WHERE c.id IS NULL"); + Wt::Dbo::collection res = session.getDboSession().query>( + "SELECT c_t from cluster_type c_t" + " LEFT OUTER JOIN cluster c ON c_t.id = c.cluster_type_id") + .where("c.id IS NULL"); return std::vector(res.begin(), res.end()); } +std::vector +ClusterType::getAllUsed(Session& session) +{ + session.checkSharedLocked(); + + Wt::Dbo::collection res = session.getDboSession().query>( + "SELECT DISTINCT c_t from cluster_type c_t") + .join("cluster c ON c_t.id = c.cluster_type_id"); + + return std::vector(res.begin(), res.end()); +} ClusterType::pointer ClusterType::getByName(Session& session, const std::string& name) diff --git a/src/libs/database/include/database/Cluster.hpp b/src/libs/database/include/database/Cluster.hpp index fb0e4518..71e0da7f 100644 --- a/src/libs/database/include/database/Cluster.hpp +++ b/src/libs/database/include/database/Cluster.hpp @@ -92,6 +92,7 @@ class ClusterType : public Wt::Dbo::Dbo ClusterType(std::string name); static std::vector getAllOrphans(Session& session); + static std::vector getAllUsed(Session& session); static pointer getByName(Session& session, const std::string& name); static pointer getById(Session& session, IdType id); static std::vector getAll(Session& session); diff --git a/src/lms/ui/explore/Filters.cpp b/src/lms/ui/explore/Filters.cpp index e893ba40..06c34da9 100644 --- a/src/lms/ui/explore/Filters.cpp +++ b/src/lms/ui/explore/Filters.cpp @@ -52,7 +52,7 @@ Filters::showDialog() { auto transaction {LmsApp->getDbSession().createSharedTransaction()}; - const auto types {Database::ClusterType::getAll(LmsApp->getDbSession())}; + const auto types {Database::ClusterType::getAllUsed(LmsApp->getDbSession())}; for (const Database::ClusterType::pointer& type : types) typeCombo->addItem(Wt::WString::fromUTF8(type->getName())); diff --git a/src/test/database/DatabaseTest.cpp b/src/test/database/DatabaseTest.cpp index d12e3c52..6569f1a4 100644 --- a/src/test/database/DatabaseTest.cpp +++ b/src/test/database/DatabaseTest.cpp @@ -228,7 +228,6 @@ testSingleCluster(Session& session) { auto transaction {session.createUniqueTransaction()}; - auto clusters {Cluster::getAll(session)}; CHECK(clusters.size() == 1); CHECK(clusters.front().id() == cluster.getId()); @@ -242,6 +241,10 @@ testSingleCluster(Session& session) CHECK(clusterTypes.size() == 1); CHECK(clusterTypes.front().id() == clusterType.getId()); + clusterTypes = ClusterType::getAllUsed(session); + CHECK(clusterTypes.size() == 1); + CHECK(clusterTypes.front().id() == clusterType.getId()); + clusterTypes = ClusterType::getAllOrphans(session); CHECK(clusterTypes.empty()); } @@ -253,6 +256,8 @@ testSingleCluster(Session& session) auto clusterTypes {ClusterType::getAllOrphans(session)}; CHECK(clusterTypes.size() == 1); CHECK(clusterTypes.front().id() == clusterType.getId()); + + CHECK(ClusterType::getAllUsed(session).empty()); } }