Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 31ca3a70

Von Christian Ehringfeld vor fast 9 Jahren hinzugefügt

  • ID 31ca3a7021160b69d21dc147bbaac1a119702f99
  • Vorgänger 0e75e425
  • Nachfolger 3bc1dde3

bugfix for one-to-many attributes and testcases updated

Unterschiede anzeigen:

src/entitymanager.cpp
if (entity.data() && entity->getId() > -1) {
auto e = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(attr));
if (e) {
QSqlQuery q = this->schema->getQueryBuilder()->oneToMany(attr->getTableName(),
attr->getColumnName(), entity->getId());
QSqlQuery q = this->schema->getQueryBuilder()->oneToMany(attr->getRelatedTable(),
attr->getRelatedColumnName(), entity->getId());
auto listMap = this->convertQueryResult(q);
auto entities = this->convert(listMap, EntityHelper::getClassname(e.data()),
refresh);
tests/em/tst_em.cpp
QSharedPointer<Person> p3 = QSharedPointer<Person>(new Person("Fenja", "Sey.",
Person::Gender::FEMALE, "fenja.jpeg", "", "Lotta", QDate(1990, 11, 11)));
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("TestGroup"));
QSharedPointer<Group> g2 = QSharedPointer<Group>(new Group("TestGroup2"));
g->setLeader(p1);
g2->setLeader(p2);
g->setPersons({p1});
auto gEnt = g.objectCast<Entity>();
auto pEnt = p3.objectCast<Entity>();
auto pEnt1 = p1.objectCast<Entity>();
QVERIFY(this->e->save(gEnt));
auto maintainedGroups = p1->getMaintainedGroups();
maintainedGroups.append(g2);
p1->setMaintainedGroups(maintainedGroups);
this->e->merge(pEnt1, true, false, true);
QVERIFY(p1->getId() > -1);
QVERIFY(p1->getMaintainedGroups().size() > 0);
QCOMPARE(p1->getMaintainedGroups().size(), 2);
QVERIFY(p1->getGroups().size() > 0);
g->addPerson(p2);
g->setName("TestGroupExtended");
tests/em/tst_querybuilder.cpp
Person::Gender::FEMALE, "kristina.jpeg", "", "", QDate(1996, 5, 17)));
QSharedPointer<Group> g = QSharedPointer<Group>(new Group("Group Psy"));
QSharedPointer<Group> g2 = QSharedPointer<Group>(new Group("Group Health"));
QSharedPointer<Group> g3 = QSharedPointer<Group>(new Group("Group ABC"));
g->setLeader(p1);
g3->setLeader(p3);
g3->setPersons({p3});
g->setPersons({p1, p2, p4});
g2->setLeader(p3);
g2->setPersons({p3});
......
wg->addWorker(p3);
auto gEnt = g.objectCast<Entity>();
auto g2Ent = g2.objectCast<Entity>();
auto g3Ent = g3.objectCast<Entity>();
auto wgEnt = wg.objectCast<Entity>();
auto p5Ent = p5.objectCast<Entity>();
auto p6Ent = p6.objectCast<Entity>();
......
QVERIFY(this->e->save(wgEnt));
QVERIFY(this->e->save(g2Ent));
QVERIFY(this->e->save(p6Ent));
QVERIFY(this->e->save(g3Ent));
} catch(QString s) {
qWarning() << s;
}
......
QSharedPointer<Employee> p = e->findEntityByAttributes<Employee>(attributes, true);
QVERIFY(p);
QCOMPARE(p->getNickName(), QString("Lotta"));
QCOMPARE(p->getGroups().size(), 2);
attributes.clear();
attributes["name"] = "Group ABC";
QCOMPARE(p->getMaintainedGroups().size(), 2);
QSharedPointer<Group> g = e->findEntityByAttributes<Group>(attributes, true);
QVERIFY(g->getLeader());
QCOMPARE(g->getLeader()->getFirstName(), QString("Fenja"));
QCOMPARE(g->getLeader()->getFamilyName(), QString("Sey."));
}
void QuerybuilderTest::testFindByAttributesManyToOneRelation() {

Auch abrufbar als: Unified diff