commit f9dccfc539f4c0b8e4acc2c0a77de8e8200b28fa
Author: Christian Ehringfeld <c.ehringfeld@t-online.de>
Date:   Tue Dec 29 20:53:00 2015 +0100

    m-n

diff --git a/src/attribute.cpp b/src/attribute.cpp
index 450bd53..af3ff6e 100644
--- a/src/attribute.cpp
+++ b/src/attribute.cpp
@@ -19,8 +19,8 @@ Attribute::Attribute(QString name, QString columnName, QString tableName,
 }
 
 QString Attribute::toString() const {
-    return this->name + " " + this->columnName + " " + this->tableName + " " +
-           this->relatedTable + " " + this->relatedColumnName + " " + this->conjunctedTable;
+    return ("Attribute: " + this->name + " " + this->columnName + " " + this->tableName + " " +
+           this->relatedTable + " " + this->relatedColumnName + " " + this->conjunctedTable);
 }
 
 
diff --git a/src/attributeresolver.cpp b/src/attributeresolver.cpp
index 2360288..3cac19f 100644
--- a/src/attributeresolver.cpp
+++ b/src/attributeresolver.cpp
@@ -1,6 +1,7 @@
 #include "attributeresolver.h"
 #include "entityhelper.h"
 #include "querybuilder.h"
+#include <QDebug>
 using namespace CuteEntityManager;
 
 AttributeResolver::AttributeResolver(QSharedPointer<QueryBuilder> queryBuilder) {
@@ -39,22 +40,28 @@ Attribute *AttributeResolver::resolveManyToManyAttribute(const QSharedPointer<En
         const QString &attr, const Relation &r, const QSharedPointer<Entity> &target) {
     auto ptr = e;
     QString attributeName = r.getPropertyName();
+    QString foreignColumnName = target->getTablename();
+    auto baseObj = EntityHelper::getBaseClassObject(e, attributeName);
+    Entity* foreignBaseObj = target.data();
     if (!r.getMappedBy().isEmpty()) {
         ptr = target;
         attributeName = r.getMappedBy();
+        foreignBaseObj = EntityHelper::getBaseClassObject(ptr, attributeName);
+        foreignColumnName = foreignBaseObj->getTablename();
     }
-    auto obj = EntityHelper::getBaseClassObject(e, attributeName);
-    /**
-     * @todo check inheritance and mappedBy
-     */
     Attribute *attrObj = new Attribute(attr,
-                                       this->qb->generateColumnNameID(obj->getTablename()),
-                                       e->getTablename(), e->metaObject());
+                                       this->qb->generateColumnNameID(baseObj->getTablename()),
+                                       baseObj->getTablename(), e->metaObject());
     this->resolveInheritance(e, attrObj);
-    attrObj->setRelation(target->getTablename(), target->metaObject(), r,
-                         this->qb->generateManyToManyTableName(target->getTablename(), attributeName),
-                         this->qb->generateColumnNameID(target->getTablename()));
-    delete obj;
+    attrObj->setRelation(foreignBaseObj->getTablename(), target->metaObject(), r,
+                         this->qb->generateManyToManyTableName(foreignBaseObj->getTablename(), attributeName),
+                         this->qb->generateColumnNameID(foreignColumnName));
+    delete baseObj;
+    if(foreignBaseObj != target.data()) {
+        delete foreignBaseObj;
+    }
+
+    qDebug() << "RESOLVE";
     return attrObj;
 }
 
