Revision 48245e6a
Von Christian Ehringfeld vor etwa 10 Jahren hinzugefügt
| 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
fix