Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 48245e6a

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 48245e6a71c2a9ba633bd2f2a9438e17af9eeb98
  • Vorgänger 66704054
  • Nachfolger 4b90a7ee

fix

Unterschiede anzeigen:

src/entityhelper.cpp
}
}
void EntityHelper::removeEntityFromListProperty(const QSharedPointer<Entity>
&entity, QSharedPointer<Entity> remove, const QMetaProperty &property) {
QVariant var = property.read(entity.data());
if (!var.isNull() && var.canConvert<QList<QVariant>>()) {
auto list = EntityInstanceFactory::castQVariantList(var);
for (int i = 0; i < list.size(); ++i) {
auto e = list.at(i);
if(e->getId() == remove->getId()) {
list.removeAt(i);
EntityHelper::setListProperty(entity, list, property);
break;
}
}
}
}
void EntityHelper::setProperty(const QSharedPointer<Entity> &entity,
QSharedPointer<Entity> value,
const QMetaProperty &property) {
src/entityhelper.h
static const QString getClassName(const Entity *entity);
static void addEntityToListProperty(const QSharedPointer<Entity> &entity,
QSharedPointer<Entity> add, const QMetaProperty &property);
static void removeEntityFromListProperty(const QSharedPointer<Entity> &entity,
QSharedPointer<Entity> remove, const QMetaProperty &property);
static void setListProperty(const QSharedPointer<Entity> &entity,
QList<QSharedPointer<Entity>> &list,
const QMetaProperty &property);
src/entitymanager.cpp
QSqlQuery q = builder->manyToManyDelete(
tblName, builder->generateManyToManyColumnName(e),
e->getProperty(e->getPrimaryKey()).toLongLong());
bool refresh = r.getCascadeType().contains(CascadeType::REFRESH)
|| r.getCascadeType().contains(CascadeType::ALL);
bool remove = r.getCascadeType().contains(CascadeType::REMOVE)
|| r.getCascadeType().contains(CascadeType::ALL);
if (this->schema->getDatabase()->exec(q)) {
if (this->db->exec(q)) {
bool refresh = r.getCascadeType().contains(CascadeType::REFRESH)
|| r.getCascadeType().contains(CascadeType::ALL);
bool remove = r.getCascadeType().contains(CascadeType::REMOVE)
|| r.getCascadeType().contains(CascadeType::ALL);
auto fkProp = EntityHelper::mappedProperty(r, ptr);
for (int var = 0; var < list.size(); ++var) {
auto entity = list.at(var);
if (remove) {
this->remove(entity);
} else if (refresh) {
/**
not really with good performance, alternatively iterate over relation attribute and delete pointer from list
**/
this->refresh(entity);
EntityHelper::removeEntityFromListProperty(entity, e, fkProp);
}
}
}

Auch abrufbar als: Unified diff