From 93250cfa247e223ea37f5ede29615b5a2969d8b0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 29 Dec 2017 10:35:38 +0100 Subject: Fixed removal of entity --- common/modelresult.cpp | 4 +++- tests/querytest.cpp | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/common/modelresult.cpp b/common/modelresult.cpp index 95f4643..4295a44 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp @@ -318,7 +318,9 @@ template void ModelResult::remove(const Ptr &value) { auto childId = qHash(*value); - auto id = parentId(value); + //The removed entity will have no properties, but we at least need the parent property. + auto actualEntity = mEntities.value(childId); + auto id = parentId(actualEntity); auto parent = createIndexFromId(id); SinkTraceCtx(mLogCtx) << "Removed entity" << childId; auto index = mTree[id].indexOf(childId); diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 3b62f56..6279fa9 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -263,7 +263,6 @@ private slots: query.resourceFilter("sink.dummy.instance1"); query.requestTree(); - // We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(), 1); @@ -274,9 +273,15 @@ private slots: VERIFYEXEC(Sink::Store::create(subfolder)); VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + //Ensure the folder appears model->fetchMore(model->index(0, 0)); QTRY_VERIFY(model->data(model->index(0, 0), Sink::Store::ChildrenFetchedRole).toBool()); QCOMPARE(model->rowCount(model->index(0, 0)), 1); + + //...and dissapears again after removal + VERIFYEXEC(Sink::Store::remove(subfolder)); + VERIFYEXEC(Sink::ResourceControl::flushMessageQueue("sink.dummy.instance1")); + QTRY_COMPARE(model->rowCount(model->index(0, 0)), 0); } void testMailByMessageId() -- cgit v1.2.3