commit a873a3ba62ec8906c8621fdc4d3c0a345427054a
Author: Christian Ehringfeld <c.ehringfeld@t-online.de>
Date:   Thu Mar 24 16:32:04 2016 +0100

    closes #614

diff --git a/src/cache.cpp b/src/cache.cpp
index 59f860c..2d761cd 100644
--- a/src/cache.cpp
+++ b/src/cache.cpp
@@ -17,9 +17,8 @@
 #include "entityhelper.h"
 using namespace CuteEntityManager;
 Cache::Cache() {
-
 }
-QHash<QString, QWeakPointer<Entity> > Cache::getCache() const {
+QHash<QString, QWeakPointer<Entity>> Cache::getCache() const {
     return cache;
 }
 
@@ -35,6 +34,10 @@ bool Cache::contains(const QString &key) {
     return false;
 }
 
+void Cache::clear() {
+    this->cache.clear();
+}
+
 void Cache::insert(QSharedPointer<Entity> &entity) {
     if (entity && entity->getId() > -1) {
         QString key = this->generateKey(entity->getId(),
diff --git a/src/cache.h b/src/cache.h
index a6bef82..2c1fd69 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -39,6 +39,7 @@ class Cache {
         }
         return ok;
     }
+    void clear();
     void insert(QSharedPointer<Entity> &entity);
     void remove(const QSharedPointer<Entity> &entity);
     void remove(const qint64 &id, const QString &classname);
diff --git a/src/entityinspector.cpp b/src/entityinspector.cpp
index 49708bd..9efd3bd 100644
--- a/src/entityinspector.cpp
+++ b/src/entityinspector.cpp
@@ -15,7 +15,6 @@
  */
 #include "entityinspector.h"
 #include <QDir>
-#include <QDebug>
 #include <QDateTime>
 using namespace CuteEntityManager;
 
@@ -105,7 +104,6 @@ void EntityInspector::checkMetaProperties(QHash<QString, QMetaProperty>
         if (typeName.contains("QSharedPointer") && !relations.contains(i.key())) {
             ok = false;
             msg += "No relation defined for attribute " + i.key() + "!\n";
-
         } else if (typeName.contains("QPointer")) {
             ok = false;
             msg += i.key() + " must use QSharedPointer.\n";
@@ -231,7 +229,6 @@ void EntityInspector::checkRelationTypes(const Relation &r,
             && foreign.getType() != RelationType::ONE_TO_ONE) {
         ok = false;
         this->logRelationTypeErrorMsg("ONE_TO_ONE", r, foreign);
-
     } else if (r.getType() == RelationType::MANY_TO_MANY
                && foreign.getType() != RelationType::MANY_TO_MANY) {
         this->logRelationTypeErrorMsg("MANY_TO_MANY", r, foreign);
@@ -332,6 +329,11 @@ bool EntityInspector::checkPrimaryKey(Entity *&entity) {
                              " for primary key not exists. Please check your getPrimaryKey() method!\n",
                              MsgType::CRITICAL);
     }
+    if(metaprops.size() <= 1) {
+        ok = false;
+        this->logger->logMsg("Entity has only one attribute. Please add attributes. Otherwise you can run into problems.",
+                             MsgType::CRITICAL);
+    }
     return ok;
 }
 
diff --git a/src/entitymanager.cpp b/src/entitymanager.cpp
index f8bacb0..c627281 100644
--- a/src/entitymanager.cpp
+++ b/src/entitymanager.cpp
@@ -88,6 +88,10 @@ QSharedPointer<QueryBuilder> EntityManager::getQueryBuilder() const {
     return this->schema->getQueryBuilder();
 }
 
+void EntityManager::clearCache() {
+    this->cache.clear();
+}
+
 bool EntityManager::saveObject(QSharedPointer<Entity> &entity,
                                QList<Entity *> &mergedObjects, const bool persistRelations,
                                const bool ignoreHasChanged, const bool validate,
@@ -453,7 +457,7 @@ void EntityManager::manyToOne(const QSharedPointer<Entity> &entity,
         QString className = attr->getRelatedClass()->className();
         QSharedPointer<Entity> ptr = QSharedPointer<Entity>();
         if (!(this->cache.contains(convertedId, className)
-                         && (ptr = this->cache.get(convertedId, className)))) {
+                && (ptr = this->cache.get(convertedId, className)))) {
             ptr = this->findById(convertedId, className);
         }
         EntityHelper::setProperty(entity, ptr, attr->getMetaProperty());
@@ -466,8 +470,8 @@ void EntityManager::oneToMany(const QSharedPointer<Entity> &entity,
         auto e = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(attr));
         if (e) {
             Query query = this->schema->getQueryBuilder()->oneToMany(
-                        attr->getRelatedTable(),
-                        attr->getRelatedColumnName(), entity->getId());
+                              attr->getRelatedTable(),
+                              attr->getRelatedColumnName(), entity->getId());
             QSqlQuery q = this->queryInterpreter->build(query);
             auto listMap = this->convertQueryResult(q);
             auto entities = this->convert(listMap, EntityHelper::getClassname(e.data()));
@@ -828,7 +832,7 @@ void EntityManager::manyToMany(const QSharedPointer<Entity> &entity,
             for (int var = 0; var < listMap.size(); ++var) {
                 auto id = listMap.at(var).value(attr->getRelatedColumnName());
                 if (!(this->cache.contains(id.toLongLong(), secClassName) &&
-                                 (e = this->cache.get(id.toLongLong(), secClassName)))) {
+                        (e = this->cache.get(id.toLongLong(), secClassName)))) {
                     e = this->findById(id.toLongLong(), secClassName);
                 }
                 if (e) {
@@ -842,10 +846,11 @@ void EntityManager::manyToMany(const QSharedPointer<Entity> &entity,
     }
 }
 
-QList<QSharedPointer<Entity>> EntityManager::findEntityByAttributes(const QSharedPointer<Entity> &entity,
+QList<QSharedPointer<Entity>> EntityManager::findEntityByAttributes(
+                               const QSharedPointer<Entity> &entity,
 bool ignoreID, const bool resolveRelations) {
     auto maps = this->findAllByAttributes(entity, ignoreID);
-    return this->convert(maps, EntityHelper::getClassname(entity.data()),resolveRelations);
+    return this->convert(maps, EntityHelper::getClassname(entity.data()), resolveRelations);
 }
 
 QHash<QString, QVariant> EntityManager::findByPk(qint64 id,
@@ -1052,7 +1057,7 @@ QList<QSharedPointer<Entity>> EntityManager::convert(
 const char *classname, const bool resolveRelations) {
     auto list = QList<QSharedPointer<Entity>>();
     for (int var = 0; var < maps.size(); ++var) {
-        auto ptr = this->convert(maps.at(var), classname,resolveRelations);
+        auto ptr = this->convert(maps.at(var), classname, resolveRelations);
         list.append(ptr);
     }
     return list;
diff --git a/src/entitymanager.h b/src/entitymanager.h
index ffcd817..c99762c 100644
--- a/src/entitymanager.h
+++ b/src/entitymanager.h
@@ -159,7 +159,11 @@ class EntityManager : public QObject {
     static EntityManager *getDefaultInstance();
     static EntityManager *getInstance(QString name);
     QSharedPointer<QueryBuilder> getQueryBuilder() const;
-
+    /**
+     * @brief clearCache
+     * don't use this function. It's only for test purposes.
+     */
+    void clearCache();
     template<class T> QList<QSharedPointer<T>> find(Query &q,
                                             const bool joinBaseClasses = false, const bool resolveRelations = true) {
         QSharedPointer<Entity> ptr = QSharedPointer<Entity>
diff --git a/src/querybuilder.cpp b/src/querybuilder.cpp
index d343706..8aa3bd5 100644
--- a/src/querybuilder.cpp
+++ b/src/querybuilder.cpp
@@ -577,10 +577,6 @@ Query QueryBuilder::findByAttributes(const QHash<QString, QVariant> &m,
     q.appendWhere(Expression(this->where(m, this->andKeyword(), ignoreID, "id", false), m));
     q.setLimit(limit);
     q.setOffset(offset);
-//    QSqlQuery q = this->database->getQuery(this->selectBase(QStringList(
-//            tableName)) + this->where(m, this->andKeyword(), ignoreID) + this->limit(limit,
-//                                           offset));
-//    this->bindValues(m, q, ignoreID);
     return q;
 }
 
diff --git a/tests/em/tst_querybuilder.cpp b/tests/em/tst_querybuilder.cpp
index 9117a98..e0a3074 100644
--- a/tests/em/tst_querybuilder.cpp
+++ b/tests/em/tst_querybuilder.cpp
@@ -322,11 +322,13 @@ void QuerybuilderTest::testQueryBuilderManyToManyRelationAttribute() {
 }
 
 void QuerybuilderTest::testRefresh() {
+    e->clearCache();
     auto persons = e->findAll<Person>(false);
     QCOMPARE(persons.first()->getGroups().size(), 0);
     QHash<QString, QVariant> attributes;
     attributes["name"] = QString("Group Health");
-    QSharedPointer<Group> g = this->e->findEntityByAttributes<Group>(attributes, false, false);
+    QSharedPointer<Group> g = this->e->findEntityByAttributes<Group>(attributes, false,
+                              false);
     QCOMPARE(g->getPersons().count(), 0);
     auto entity = g.objectCast<Entity>();
     e->refresh(entity, true);
