Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 554f7bc0

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 554f7bc0fd2eac31e6949ff54ad37b22fd286d7f
  • Vorgänger fc14f551
  • Nachfolger d2c33642

has changed method

Unterschiede anzeigen:

samples/example/main.cpp
qWarning() << "-----------------------------";
QSharedPointer<Entity> personFindPtr = e->findById(1, QString("Person"));
qDebug() << "HASCHANGED:" << e->hasChanged(personFindPtr);
e->refresh(personFindPtr);
QSharedPointer<Person> pers = personFindPtr.objectCast<Person>();
qWarning() << "MainTeacher:" << personFindPtr->toString();
src/entitymanager.cpp
return !entity->hasErrors();
}
bool EntityManager::hasChanged(QSharedPointer<Entity> &entity) {
bool changed = true;
if (entity->getId() >= -1) {
changed = false;
auto listmap = this->findByPk(entity->getId(), entity);
auto relations = entity->getRelations();
QStringList rels = QStringList();
for (auto i = relations.constBegin(); i != relations.constEnd(); ++i) {
if (i.value().getType() == RelationType::MANY_TO_ONE
|| (i.value().getType() == RelationType::ONE_TO_ONE
&& i.value().getMappedBy().isEmpty())) {
rels.append(this->schema->getQueryBuilder()->generateColumnNameID(i.key()));
}
}
for (auto i = listmap.constBegin(); i != listmap.constEnd(); ++i) {
if (rels.contains(i.key())) {
QString appendix =
this->schema->getQueryBuilder()->columnNameIDAppendix();
QString relKey = i.key();
QVariant v = entity->getProperty(relKey.remove(relKey.size() - appendix.size(),
appendix.size()));
if (!v.isNull()) {
auto entity = EntityInstanceFactory::castQVariant(v);
if (entity->getProperty(entity->getPrimaryKey()) != i.value()) {
changed = true;
break;
}
}
} else {
QVariant property = entity->getProperty(i.key());
changed = i.value() != property && !(i.value().isNull() && property.isNull());
if (changed) {
break;
}
}
}
}
return changed;
}
QString EntityManager::createConnection() {
QStringList l = EntityManager::getConnectionNames();
QString conName = "";
src/entitymanager.h
QList<QHash<QString, QVariant> > selectBySql(const QString &sql);
qint8 count(Query &query);
bool validate(QSharedPointer<Entity> &entity);
bool hasChanged(QSharedPointer<Entity> &entity);
public:
EntityManager(QSqlDatabase database, bool logQueries = false);
src/querybuilder.cpp
}
QString QueryBuilder::generateColumnNameID(QString name) const {
return name.append("_id");
return name.append(this->columnNameIDAppendix());
}
QString QueryBuilder::columnNameIDAppendix() const {
return "_id";
}
QString QueryBuilder::getForeignKeyCascade(DbForeignKeyCascade cascade) const {
src/querybuilder.h
QString generateIndexName(const QString &name, const QString &table,
const QString &refColumn, const QString &refTable, const bool fk) const;
QString generateColumnNameID(QString name) const;
QString columnNameIDAppendix() const;
virtual void createRelationFK(QStringList &queries,
const QSharedPointer<Entity> &entity, const Relation &relation,
const QMetaProperty &metaProperty, const QString &update,

Auch abrufbar als: Unified diff