Revision a473cd61
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
samples/example/main.cpp | ||
---|---|---|
groupFindPtr->setName("10b");
|
||
qWarning() << groupFindPtr->toString();
|
||
QSharedPointer<Entity> entityGroupFindPtr = groupFindPtr.objectCast<Entity>();
|
||
e->save(entityGroupFindPtr, false);
|
||
e->save(entityGroupFindPtr, true);
|
||
|
||
qWarning() << "-----------------------------";
|
||
qWarning() << "Remove Group";
|
||
qWarning() << "-----------------------------";
|
||
e->remove(entityGroupFindPtr);
|
||
//e->remove(entityGroupFindPtr);
|
||
|
||
|
||
|
src/entitymanager.cpp | ||
---|---|---|
if (r.getType() == RelationType::MANY_TO_ONE) {
|
||
auto e = EntityInstanceFactory::castQVariant(var);
|
||
if (this->shouldBeSaved(e, r)) {
|
||
this->save(e);
|
||
this->save(e, true, false);
|
||
auto fkProp = EntityHelper::mappedProperty(r, e);
|
||
if (fkProp.isValid()) {
|
||
EntityHelper::addEntityToListProperty(e, entity, fkProp);
|
||
... | ... | |
} else if (r.getType() == RelationType::ONE_TO_ONE
|
||
&& r.getMappedBy().isEmpty()) {
|
||
auto e = EntityInstanceFactory::castQVariant(var);
|
||
this->save(e);
|
||
this->save(e, true, false);
|
||
auto prop = EntityHelper::mappedProperty(r, e);
|
||
if (prop.isValid()) {
|
||
EntityHelper::setProperty(e, entity, prop);
|
||
... | ... | |
for (int var = 0; var < list.size(); ++var) {
|
||
auto e = list.at(var);
|
||
if (this->shouldBeSaved(e, r)) {
|
||
this->save(e);
|
||
this->save(e, true, false);
|
||
if (fkProp.isValid()) {
|
||
EntityHelper::addEntityToListProperty(e, entity, fkProp);
|
||
}
|
||
... | ... | |
} else if (r.getType() == RelationType::ONE_TO_ONE
|
||
&& !r.getMappedBy().isEmpty()) {
|
||
auto e = EntityInstanceFactory::castQVariant(var);
|
||
this->save(e);
|
||
if (this->hasChanged(e)) {
|
||
this->save(e, true, false);
|
||
}
|
||
auto fkProp = EntityHelper::mappedProperty(r, e);
|
||
if (fkProp.isValid()) {
|
||
EntityHelper::addEntityToListProperty(e, entity, fkProp);
|
||
... | ... | |
QSharedPointer<Entity> ptr;
|
||
for (int var = 0; var < list.size(); ++var) {
|
||
ptr = list.at(var);
|
||
if (this->shouldBeSaved(ptr, r) && this->hasChanged(ptr) && this->save(ptr)) {
|
||
if ((this->shouldBeSaved(ptr, r) && this->save(ptr, true, false))
|
||
|| ptr->getProperty(ptr->getPrimaryKey()).toLongLong() > -1) {
|
||
saved.append(ptr);
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
|
||
bool EntityManager::save(QSharedPointer<Entity> &entity,
|
||
const bool persistRelations) {
|
||
if (entity->getProperty(entity->getPrimaryKey()).toLongLong() > -1) {
|
||
return this->merge(entity, persistRelations);
|
||
} else {
|
||
return this->create(entity, persistRelations);
|
||
const bool persistRelations, const bool ignoreHasChanged) {
|
||
if (ignoreHasChanged || (!ignoreHasChanged && this->hasChanged(entity))) {
|
||
if (entity->getProperty(entity->getPrimaryKey()).toLongLong() > -1) {
|
||
return this->merge(entity, persistRelations);
|
||
} else {
|
||
return this->create(entity, persistRelations);
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
qint64 EntityManager::findId(QSharedPointer<Entity> &entity) {
|
src/entitymanager.h | ||
---|---|---|
const bool persistRelations = true, const bool validate = true);
|
||
bool create(QSharedPointer<Entity> &entity, const bool persistRelations = true,
|
||
const bool checkDuplicate = false, const bool validate = true);
|
||
bool save(QSharedPointer<Entity> &entity, const bool persistRelations = true);
|
||
bool save(QSharedPointer<Entity> &entity, const bool persistRelations = true, const bool ignoreHasChanged=true);
|
||
qint64 findId(QSharedPointer<Entity> &entity);
|
||
bool merge(QSharedPointer<Entity> &entity, bool withRelations = true,
|
||
const bool validate = true);
|
Auch abrufbar als: Unified diff
more stuff for #578