Revision 2ce163c3
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
src/entityinstancefactory.cpp | ||
---|---|---|
while (iterator != attributes.constEnd()) {
|
||
if (metaprops.contains(iterator.key())) {
|
||
QMetaProperty prop = metaprops.value(iterator.key());
|
||
if (!(prop.isWritable() && prop.write(e, iterator.value()))) {
|
||
if(prop.isWritable()) {
|
||
if(prop.isEnumType()) {
|
||
prop.write(e,prop.enumerator().key(iterator.value().toInt()));
|
||
} else {
|
||
prop.write(e, iterator.value());
|
||
}
|
||
} else {
|
||
qDebug() << prop.name() << "on Entity" << e->getClassname() << "not writeable!";
|
||
}
|
||
}
|
src/entitymanager.cpp | ||
---|---|---|
const char *classname, const bool refresh) {
|
||
auto ptr = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(
|
||
classname, map));
|
||
this->resolveRelations(ptr, map, refresh);
|
||
this->cache.insert(ptr);
|
||
this->resolveRelations(ptr, map, refresh);
|
||
return ptr;
|
||
}
|
||
|
||
... | ... | |
QSharedPointer<Entity> secEntityPtr = QSharedPointer<Entity>(secEntity);
|
||
QString tblName = builder->generateManyToManyTableName(entity,
|
||
secEntityPtr);
|
||
/**
|
||
* maybe it would be better, to fetch first the ids, look up cache and then request missing entities
|
||
* with this it would be also possible to respect cascade type
|
||
*/
|
||
if (this->schema->getTables().contains(tblName)) {
|
||
QSqlQuery q = builder->manyToMany(tblName,
|
||
builder->generateManyToManyColumnName(entity),
|
||
entity->getProperty(entity->getPrimaryKey()).toLongLong(),
|
||
builder->generateManyToManyColumnName(secEntityPtr),
|
||
secEntityPtr->getTablename());
|
||
entity->getProperty(entity->getPrimaryKey()).toLongLong());
|
||
auto listMap = this->convertQueryResult(q);
|
||
auto entities = this->convert(listMap, entity->getClassname(), refresh);
|
||
auto entities = QList<QSharedPointer<Entity> >();
|
||
for (int var = 0; var < listMap.size(); ++var) {
|
||
auto id = listMap.at(var).value(builder->generateManyToManyColumnName(
|
||
secEntityPtr));
|
||
if (!refresh
|
||
&& this->cache.contains(id.toLongLong(), secEntityPtr->getClassname())) {
|
||
entities.append(this->cache.get(id.toLongLong(), secEntityPtr->getClassname()));
|
||
} else {
|
||
entities.append(this->findById(id.toLongLong(), secEntityPtr->getClassname()));
|
||
}
|
||
}
|
||
this->setListProperty(entity, entities, property);
|
||
} else {
|
||
qDebug() << "MANY_TO_MANY Table " << tblName << " not exists";
|
||
... | ... | |
entity->setId(-1);
|
||
rc = false;
|
||
} else {
|
||
this->cache.insert(entity);
|
||
if (persistRelations) {
|
||
this->saveRelations(entity);
|
||
}
|
||
this->cache.insert(entity);
|
||
rc = true;
|
||
}
|
||
}
|
src/querybuilder.cpp | ||
---|---|---|
|
||
QSqlQuery QueryBuilder::manyToMany(const QString &tableName,
|
||
const QString &attribute,
|
||
const qint64 &id,
|
||
const QString &foreignKey, const QString &foreignTable) {
|
||
const qint64 &id) {
|
||
QSqlQuery q = this->database->getQuery();
|
||
QString sql = this->selectBase(QStringList(tableName),
|
||
QStringList(foreignTable + ".*")) + " " + this->leftJoin(
|
||
foreignTable, tableName,
|
||
foreignKey) + " WHERE " + this->schema->quoteColumnName(
|
||
attribute) + "=:id;";
|
||
QString sql = this->selectBase(QStringList(tableName), QStringList("*"));
|
||
sql += " WHERE ";
|
||
sql += this->schema->quoteColumnName(
|
||
attribute);
|
||
sql += " = :id;";
|
||
q.prepare(sql);
|
||
q.bindValue(":id", QVariant(id));
|
||
q.bindValue(":id", id);
|
||
return q;
|
||
}
|
||
|
src/querybuilder.h | ||
---|---|---|
const qint64 &id,
|
||
const qint64 &limit = 0);
|
||
QSqlQuery manyToMany(const QString &tableName, const QString &attribute,
|
||
const qint64 &id,
|
||
const QString &foreignKey,
|
||
const QString &foreignTable);
|
||
const qint64 &id);
|
||
QSqlQuery manyToManyDelete(const QString &tableName, const QString &attribute,
|
||
const qint64 &id);
|
||
QSqlQuery manyToManyInsert(const QString &tableName, const QString &col1,
|
Auch abrufbar als: Unified diff
many_many selection works