commit 75cecd6788d56ed391e44e354609ec91116335db
Author: Christian Ehringfeld <c.ehringfeld@t-online.de>
Date:   Sun Sep 4 00:37:27 2016 +0200

    hmm

diff --git a/samples/example/models/address.h b/samples/example/models/address.h
index 243d66c..7f44ad5 100644
--- a/samples/example/models/address.h
+++ b/samples/example/models/address.h
@@ -10,6 +10,7 @@ class Relation;
 class Pupil;
 class Address: public CuteEntityManager::Entity {
     Q_OBJECT
+    EM_MACRO(Address)
 
     Q_PROPERTY(QString label READ getLabel WRITE setLabel)
     Q_PROPERTY(QString street READ getStreet WRITE setStreet)
diff --git a/samples/example/models/contact.h b/samples/example/models/contact.h
index 8a89830..aa3a684 100644
--- a/samples/example/models/contact.h
+++ b/samples/example/models/contact.h
@@ -9,6 +9,7 @@ class Person;
 class Pupil;
 class Contact: public CuteEntityManager::Entity {
     Q_OBJECT
+    EM_MACRO(Contact)
 
     Q_PROPERTY(QString content READ getContent WRITE setContent)
     Q_PROPERTY(Category category READ getCategory WRITE setCategory)
diff --git a/samples/example/models/group.h b/samples/example/models/group.h
index 03c3980..5204c81 100644
--- a/samples/example/models/group.h
+++ b/samples/example/models/group.h
@@ -11,6 +11,7 @@ using namespace CuteEntityManager;
 
 class Group: public CuteEntityManager::Entity {
     Q_OBJECT
+    EM_MACRO(Group)
     Q_PROPERTY(QList<QSharedPointer<Pupil>> pupils READ getPupils WRITE setPupils)
     Q_PROPERTY(QList<QSharedPointer<Person>> persons READ getPersons WRITE
                setPersons)
diff --git a/samples/example/models/person.h b/samples/example/models/person.h
index fb3fde9..56ed902 100644
--- a/samples/example/models/person.h
+++ b/samples/example/models/person.h
@@ -16,6 +16,7 @@ class Address;
 
 class Person: public Entity {
     Q_OBJECT
+    EM_MACRO(Person)
     Q_PROPERTY(QString firstName READ getFirstName WRITE setFirstName)
     Q_PROPERTY(QString familyName READ getFamilyName WRITE setFamilyName)
     Q_PROPERTY(QString namePrefix READ getNamePrefix WRITE setNamePrefix)
diff --git a/samples/example/models/pupil.h b/samples/example/models/pupil.h
index c3dc9db..33b1440 100644
--- a/samples/example/models/pupil.h
+++ b/samples/example/models/pupil.h
@@ -4,6 +4,7 @@
 
 class Pupil : public Person {
     Q_OBJECT
+    EM_MACRO(Pupil)
     Q_PROPERTY(QString legalGuardianNote READ getLegalGuardianNote WRITE
                setLegalGuardianNote)
   public:
diff --git a/samples/simple/article.h b/samples/simple/article.h
index 3df8968..0d2104c 100644
--- a/samples/simple/article.h
+++ b/samples/simple/article.h
@@ -24,6 +24,7 @@
 
 class Article : public CuteEntityManager::Entity {
     Q_OBJECT
+    EM_MACRO(Article)
     Q_PROPERTY(double price READ getPrice WRITE setPrice)
     Q_PROPERTY(QString name READ getName WRITE setName)
   private:
diff --git a/samples/validators/address.h b/samples/validators/address.h
index 0248af9..802f4cf 100644
--- a/samples/validators/address.h
+++ b/samples/validators/address.h
@@ -10,6 +10,7 @@ class Relation;
 class Pupil;
 class Address: public CuteEntityManager::Entity {
     Q_OBJECT
+    EM_MACRO(Address)
     Q_PROPERTY(QString label READ getLabel WRITE setLabel)
     Q_PROPERTY(QString street READ getStreet WRITE setStreet)
     Q_PROPERTY(QString postcode READ getPostcode WRITE setPostcode)
diff --git a/samples/validators/person.h b/samples/validators/person.h
index b8da6f7..c34ae3c 100644
--- a/samples/validators/person.h
+++ b/samples/validators/person.h
@@ -16,6 +16,7 @@ class Address;
 
 class Person: public Entity {
     Q_OBJECT
+    EM_MACRO(Person)
     Q_PROPERTY(QString firstName READ getFirstName WRITE setFirstName)
     Q_PROPERTY(QString familyName READ getFamilyName WRITE setFamilyName)
     Q_PROPERTY(QString namePrefix READ getNamePrefix WRITE setNamePrefix)
diff --git a/src/databasemigration.h b/src/databasemigration.h
index f819989..5f6409a 100644
--- a/src/databasemigration.h
+++ b/src/databasemigration.h
@@ -21,6 +21,7 @@
 namespace CuteEntityManager {
 class DatabaseMigration : public Entity {
     Q_OBJECT
+    EM_MACRO(DatabaseMigration)
     Q_PROPERTY(QString version READ getVersion WRITE setVersion)
     Q_PROPERTY(QDateTime applyTime READ getApplyTime WRITE setApplyTime)
 
diff --git a/src/entity.h b/src/entity.h
index d1f83ce..25a3c21 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -23,6 +23,7 @@
 #include "relation.h"
 #include "validators/validatorrule.h"
 #include "validators/errormsg.h"
+#include <QDebug>
 namespace CuteEntityManager {
 
 /**
@@ -38,12 +39,12 @@ class Entity : public QObject {
   signals:
     void idChanged();
 
-#define EM_LIST_MACRO(type) \
-    virtual void setListProperty(QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property)  { \
+#define EM_MACRO(type) \
+    virtual void setAsListProperty(const QSharedPointer<Entity> &e,QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property) override { \
         QList<QSharedPointer<type>> list = *reinterpret_cast<QList<QSharedPointer<type>>*>(&entList); \
         QVariant var; \
         var.setValue<QList<QSharedPointer<type>>>(list); \
-        property.write(this, var); \
+        property.write(e.data(), var); \
     }
 
 //#define EM_PROPERTY(type,attribute,getter,setter)
@@ -51,7 +52,7 @@ class Entity : public QObject {
 
 //#define EM_LIST_PROPERTY(type,attribute,getter,setter)
 //    Q_PROPERTY(QList<QSharedPointer<type>> attribute READ getter WRITE setter)
-//    EM_LIST_MACRO(type)
+//    EM_MACRO(type)
 
 
 
@@ -87,11 +88,7 @@ class Entity : public QObject {
     QList<ErrorMsg> getErrors() const;
     QString getErrorsAsString() const;
     void setErrors(const QList<ErrorMsg> &value);
-    virtual void setListProperty(QList<QSharedPointer<Entity>> &entList,
-                                 const QMetaProperty &property) {
-        Q_UNUSED(entList);
-        Q_UNUSED(property);
-    }
+ virtual void setAsListProperty(const QSharedPointer<Entity> &e, QList<QSharedPointer<Entity>> &entList, const QMetaProperty &property) = 0;
 
   protected:
     explicit Entity (QObject *parent = 0);
diff --git a/src/entityhelper.cpp b/src/entityhelper.cpp
index cd3f4a8..c1a8ffa 100644
--- a/src/entityhelper.cpp
+++ b/src/entityhelper.cpp
@@ -199,9 +199,11 @@ const QString EntityHelper::getClassName(const Entity *entity) {
 void EntityHelper::setListProperty(const QSharedPointer<Entity> &entity,
                                    QList<QSharedPointer<Entity>> &list,
                                    const QMetaProperty &property)  {
-    QVariant var;
-    var.setValue<QList<QSharedPointer<Entity>>>(list);
-    entity->setProperty(property.name(),var);
+    if(!list.isEmpty()) {
+        auto instance = EntityInstanceFactory::createInstance(list.at(0)->getClassname());
+        instance->setAsListProperty(entity, list, property);
+    }
+    property.reset(entity.data());
 }
 
 void EntityHelper::addEntityToListProperty(const QSharedPointer<Entity>
@@ -212,7 +214,7 @@ void EntityHelper::addEntityToListProperty(const QSharedPointer<Entity>
                                                   var) : QList<QSharedPointer<Entity>>());
     if (!list.contains(add)) {
         list.append(add);
-        entity->setListProperty(list,property);
+        EntityHelper::setListProperty(entity, list, property);
     }
 }
 
@@ -228,7 +230,7 @@ void EntityHelper::removeEntityFromListProperty(const QSharedPointer<Entity>
                 break;
             }
         }
-        entity->setListProperty(list,property);
+        EntityHelper::setListProperty(entity, list, property);
     }
 }
 
@@ -238,7 +240,7 @@ void EntityHelper::clearEntityListProperty(const QSharedPointer<Entity> &entity,
     if (var.canConvert<QList<QVariant>>()) {
         auto list = EntityInstanceFactory::castQVariantList(var);
         list.clear();
-        entity->setListProperty(list,property);
+        EntityHelper::setListProperty(entity, list, property);
     }
 }
 
diff --git a/src/entitymanager.cpp b/src/entitymanager.cpp
index edc35eb..41c21aa 100644
--- a/src/entitymanager.cpp
+++ b/src/entitymanager.cpp
@@ -444,7 +444,7 @@ void EntityManager::oneToMany(const QSharedPointer<Entity> &entity,
             QSqlQuery q = this->queryInterpreter->build(query);
             auto listMap = this->convertQueryResult(q);
             auto entities = this->convert(listMap, EntityHelper::getClassname(e.data()));
-            entity->setListProperty(entities,attr->getMetaProperty());
+            EntityHelper::setListProperty(entity,entities,attr->getMetaProperty());
         }
     }
 }
diff --git a/tests/models.h b/tests/models.h
index 3b97462..4cc8038 100644
--- a/tests/models.h
+++ b/tests/models.h
@@ -22,7 +22,7 @@ class Person: public Entity {
     Q_PROPERTY(QList<QSharedPointer<Group>> groups READ getGroups WRITE setGroups)
     Q_PROPERTY(QList<QSharedPointer<Group>> maintainedGroups READ
                getMaintainedGroups WRITE setMaintainedGroups)
-    EM_LIST_MACRO(Group)
+    EM_MACRO(Person)
 //    EM_LIST_PROPERTY(Group,groups,getGroups,setGroups)
 //    EM_LIST_PROPERTY(Group,maintainedGroups,getMaintainedGroups,setMaintainedGroups)
 
@@ -84,6 +84,7 @@ class Employee : public Person {
     Q_PROPERTY(QString department READ getDepartment WRITE setDepartment)
     Q_PROPERTY(quint64 persNumber READ getPersNumber WRITE setPersNumber)
     Q_PROPERTY(bool manager READ isManager WRITE setManager)
+    EM_MACRO(Employee)
   public:
     Employee() : Person() { }
     Employee(quint64 persNumber, QString firstName, QString familyName,
@@ -122,7 +123,7 @@ class WorkerGroup : public Entity {
     Q_PROPERTY(bool active READ isActive WRITE setActive)
     Q_PROPERTY(QList<QSharedPointer<Employee>> workers READ getWorkers WRITE
                setWorkers)
-    EM_LIST_MACRO(Employee)
+    EM_MACRO(WorkerGroup)
 
   public:
     WorkerGroup() : Entity() { }
@@ -162,7 +163,7 @@ class Group: public CuteEntityManager::Entity {
     Q_PROPERTY(QString name READ getName WRITE setName)
     Q_PROPERTY(QSharedPointer<Person> leader READ getLeader WRITE
                setLeader)
-    EM_LIST_MACRO(Person)
+    EM_MACRO(Group)
 
   public:
     Q_INVOKABLE Group();
@@ -189,6 +190,7 @@ class Article : public CuteEntityManager::Entity {
     Q_OBJECT
     Q_PROPERTY(double price READ getPrice WRITE setPrice)
     Q_PROPERTY(QString name READ getName WRITE setName)
+    EM_MACRO(Article)
   private:
     double price;
     QString name;
