commit 4677e852d618a5151f0f81f2d3d999b44c09c9dc
Author: Christian Ehringfeld <c.ehringfeld@t-online.de>
Date:   Sun Aug 2 23:44:57 2015 +0200

    fix

diff --git a/src/entitymanager.cpp b/src/entitymanager.cpp
index 6ecda9c..4eb9537 100644
--- a/src/entitymanager.cpp
+++ b/src/entitymanager.cpp
@@ -581,7 +581,7 @@ bool EntityManager::create(QList<QSharedPointer<Entity> > entities,
 bool EntityManager::create(QSharedPointer<Entity> &entity,
                            const bool persistRelations, const bool checkDuplicate) {
     bool rc = false;
-    if (this->checkTable(entity) && !(checkDuplicate && this->count(entity) == 0)) {
+    if (this->checkTable(entity) && !(checkDuplicate && this->count(entity) > 0)) {
         if (persistRelations) {
             this->savePrePersistedRelations(entity);
         }
diff --git a/src/querybuilder.cpp b/src/querybuilder.cpp
index 825cce8..7e0f30c 100644
--- a/src/querybuilder.cpp
+++ b/src/querybuilder.cpp
@@ -783,8 +783,8 @@ const {
 
 QString QueryBuilder::countFunction(const QString &distinctColumn) const {
     return QString(this->countKeyword() + "(" + (distinctColumn.isEmpty() ? "*" :
-                   (this->distinct()) +
-                   this->schema->quoteColumnName(distinctColumn)) + ")");
+                   (this->distinct() +
+                   this->schema->quoteColumnName(distinctColumn))) + ")");
 }
 
 QString QueryBuilder::distinct() const {
