{"action":"created","comment":{"url":"https://api.github.com/repos/qgis/QGIS/pulls/comments/198137465","pull_request_review_id":132011710,"id":198137465,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5ODEzNzQ2NQ==","diff_hunk":"@@ -487,9 +488,84 @@ void QgsRelationEditorWidget::deleteSelectedFeatures()\n \n void QgsRelationEditorWidget::deleteFeatures( const QgsFeatureIds &featureids )\n {\n-  QgsVectorLayer *layer = mNmRelation.isValid() ? mNmRelation.referencedLayer() : mRelation.referencingLayer();\n-  layer->deleteFeatures( featureids );\n-  updateUi();\n+  bool deleteFeatures = true;\n+\n+  QgsVectorLayer *layer;\n+  if ( mNmRelation.isValid() )\n+  {\n+    layer = mNmRelation.referencedLayer();\n+\n+    // When deleting a linked feature within an N:M relation,\n+    // check if the feature is linked to more than just one feature.\n+    // In case it is linked more than just once, ask the user for confirmation\n+    // as it is likely he was not aware of the implications and might either\n+    // leave the dataset in a corrupted state (referential integrity) or if\n+    // the fk constraint is ON CASCADE DELETE, there may be several linking\n+    // entries deleted along.\n+\n+    QgsFeatureRequest deletedFeaturesRequest;\n+    deletedFeaturesRequest.setFilterFids( featureids );\n+    deletedFeaturesRequest.setFlags( QgsFeatureRequest::NoGeometry );\n+    deletedFeaturesRequest.setSubsetOfAttributes( QgsAttributeList() << mNmRelation.referencedFields().first() );\n+\n+    QgsFeatureIterator deletedFeatures = layer->getFeatures( deletedFeaturesRequest );\n+    QStringList deletedFeaturesPks;\n+    QgsFeature feature;\n+    while ( deletedFeatures.nextFeature( feature ) )\n+    {\n+      deletedFeaturesPks.append( QgsExpression::quotedValue( feature.attribute( mNmRelation.referencedFields().first() ) ) );\n+    }\n+\n+    QgsFeatureRequest linkingFeaturesRequest;\n+    linkingFeaturesRequest.setFlags( QgsFeatureRequest::NoGeometry );\n+    linkingFeaturesRequest.setSubsetOfAttributes( QgsAttributeList() );\n+\n+    QString linkingFeaturesRequestExpression;\n+    if ( !deletedFeaturesPks.empty() )\n+    {\n+      linkingFeaturesRequestExpression = QStringLiteral( \"%1 IN (%2)\" ).arg( QgsExpression::quotedColumnRef( mNmRelation.fieldPairs().first().first ), deletedFeaturesPks.join( ',' ) );\n+      linkingFeaturesRequest.setFilterExpression( linkingFeaturesRequestExpression );\n+\n+      QgsFeatureIterator relatedLinkingFeatures = mNmRelation.referencingLayer()->getFeatures( linkingFeaturesRequest );\n+\n+      int relatedLinkingFeaturesCount = 0;\n+      while ( relatedLinkingFeatures.nextFeature( feature ) )\n+      {\n+        relatedLinkingFeaturesCount++;\n+      }\n+\n+      if ( deletedFeaturesPks.size() == 1 && relatedLinkingFeaturesCount > 1 )\n+      {\n+        QMessageBox messageBox( QMessageBox::Question, tr( \"Really delete entry?\" ), tr( \"The entry on %1 is still linked to %2 features on %3. Do you want to delete it?\" ).arg( mNmRelation.referencedLayer()->name(), QString::number( relatedLinkingFeaturesCount ), mRelation.referencedLayer()->name() ), QMessageBox::NoButton, this );\n+        messageBox.addButton( QMessageBox::Cancel );\n+        QAbstractButton *deleteButton = messageBox.addButton( tr( \"Delete\" ),  QMessageBox::AcceptRole );\n+\n+        messageBox.exec();\n+        if ( messageBox.clickedButton() != deleteButton )\n+          deleteFeatures = false;\n+      }\n+      else if ( deletedFeaturesPks.size() > 1 && relatedLinkingFeaturesCount > deletedFeaturesPks.size() )","path":"src/gui/qgsrelationeditorwidget.cpp","position":71,"original_position":71,"commit_id":"833c4221d41e1bc4d4bb8ece05882d19ef943a7e","original_commit_id":"833c4221d41e1bc4d4bb8ece05882d19ef943a7e","user":{"login":"m-kuhn","id":588407,"node_id":"MDQ6VXNlcjU4ODQwNw==","avatar_url":"https://avatars1.githubusercontent.com/u/588407?v=4","gravatar_id":"","url":"https://api.github.com/users/m-kuhn","html_url":"https://github.com/m-kuhn","followers_url":"https://api.github.com/users/m-kuhn/followers","following_url":"https://api.github.com/users/m-kuhn/following{/other_user}","gists_url":"https://api.github.com/users/m-kuhn/gists{/gist_id}","starred_url":"https://api.github.com/users/m-kuhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-kuhn/subscriptions","organizations_url":"https://api.github.com/users/m-kuhn/orgs","repos_url":"https://api.github.com/users/m-kuhn/repos","events_url":"https://api.github.com/users/m-kuhn/events{/privacy}","received_events_url":"https://api.github.com/users/m-kuhn/received_events","type":"User","site_admin":false},"body":"Let me assure you that I am very happy to have you look over the code ! :)","created_at":"2018-06-26T13:14:37Z","updated_at":"2018-06-26T13:14:37Z","html_url":"https://github.com/qgis/QGIS/pull/7315#discussion_r198137465","pull_request_url":"https://api.github.com/repos/qgis/QGIS/pulls/7315","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/qgis/QGIS/pulls/comments/198137465"},"html":{"href":"https://github.com/qgis/QGIS/pull/7315#discussion_r198137465"},"pull_request":{"href":"https://api.github.com/repos/qgis/QGIS/pulls/7315"}},"in_reply_to_id":198131755},"pull_request":{"url":"https://api.github.com/repos/qgis/QGIS/pulls/7315","id":197406653,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk3NDA2NjUz","html_url":"https://github.com/qgis/QGIS/pull/7315","diff_url":"https://github.com/qgis/QGIS/pull/7315.diff","patch_url":"https://github.com/qgis/QGIS/pull/7315.patch","issue_url":"https://api.github.com/repos/qgis/QGIS/issues/7315","number":7315,"state":"open","locked":false,"title":"Confirm delete when feature is still linked","user":{"login":"m-kuhn","id":588407,"node_id":"MDQ6VXNlcjU4ODQwNw==","avatar_url":"https://avatars1.githubusercontent.com/u/588407?v=4","gravatar_id":"","url":"https://api.github.com/users/m-kuhn","html_url":"https://github.com/m-kuhn","followers_url":"https://api.github.com/users/m-kuhn/followers","following_url":"https://api.github.com/users/m-kuhn/following{/other_user}","gists_url":"https://api.github.com/users/m-kuhn/gists{/gist_id}","starred_url":"https://api.github.com/users/m-kuhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-kuhn/subscriptions","organizations_url":"https://api.github.com/users/m-kuhn/orgs","repos_url":"https://api.github.com/users/m-kuhn/repos","events_url":"https://api.github.com/users/m-kuhn/events{/privacy}","received_events_url":"https://api.github.com/users/m-kuhn/received_events","type":"User","site_admin":false},"body":"when deleting a feature on an N:M relation and the feature in question is still linked to more than a single feature ask for confirmation. The user might not have been aware of that.\r\nFix #18755 https://issues.qgis.org/issues/18755\r\n\r\n![screenshot from 2018-06-26 12-15-13](https://user-images.githubusercontent.com/588407/41912029-a719554c-794e-11e8-8b6e-c95d8b954a69.png)\r\n\r\n![screenshot from 2018-06-26 12-15-27](https://user-images.githubusercontent.com/588407/41912028-a6fcc7d8-794e-11e8-9436-eea882c12705.png)\r\n\r\n","created_at":"2018-06-26T12:34:56Z","updated_at":"2018-06-26T13:14:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9e8310055247c2b5c2abcc8e341809413f056624","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/qgis/QGIS/pulls/7315/commits","review_comments_url":"https://api.github.com/repos/qgis/QGIS/pulls/7315/comments","review_comment_url":"https://api.github.com/repos/qgis/QGIS/pulls/comments{/number}","comments_url":"https://api.github.com/repos/qgis/QGIS/issues/7315/comments","statuses_url":"https://api.github.com/repos/qgis/QGIS/statuses/833c4221d41e1bc4d4bb8ece05882d19ef943a7e","head":{"label":"m-kuhn:confirmDeleteLinkedNm","ref":"confirmDeleteLinkedNm","sha":"833c4221d41e1bc4d4bb8ece05882d19ef943a7e","user":{"login":"m-kuhn","id":588407,"node_id":"MDQ6VXNlcjU4ODQwNw==","avatar_url":"https://avatars1.githubusercontent.com/u/588407?v=4","gravatar_id":"","url":"https://api.github.com/users/m-kuhn","html_url":"https://github.com/m-kuhn","followers_url":"https://api.github.com/users/m-kuhn/followers","following_url":"https://api.github.com/users/m-kuhn/following{/other_user}","gists_url":"https://api.github.com/users/m-kuhn/gists{/gist_id}","starred_url":"https://api.github.com/users/m-kuhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-kuhn/subscriptions","organizations_url":"https://api.github.com/users/m-kuhn/orgs","repos_url":"https://api.github.com/users/m-kuhn/repos","events_url":"https://api.github.com/users/m-kuhn/events{/privacy}","received_events_url":"https://api.github.com/users/m-kuhn/received_events","type":"User","site_admin":false},"repo":{"id":5270567,"node_id":"MDEwOlJlcG9zaXRvcnk1MjcwNTY3","name":"QGIS","full_name":"m-kuhn/QGIS","owner":{"login":"m-kuhn","id":588407,"node_id":"MDQ6VXNlcjU4ODQwNw==","avatar_url":"https://avatars1.githubusercontent.com/u/588407?v=4","gravatar_id":"","url":"https://api.github.com/users/m-kuhn","html_url":"https://github.com/m-kuhn","followers_url":"https://api.github.com/users/m-kuhn/followers","following_url":"https://api.github.com/users/m-kuhn/following{/other_user}","gists_url":"https://api.github.com/users/m-kuhn/gists{/gist_id}","starred_url":"https://api.github.com/users/m-kuhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-kuhn/subscriptions","organizations_url":"https://api.github.com/users/m-kuhn/orgs","repos_url":"https://api.github.com/users/m-kuhn/repos","events_url":"https://api.github.com/users/m-kuhn/events{/privacy}","received_events_url":"https://api.github.com/users/m-kuhn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/m-kuhn/QGIS","description":"QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)","fork":true,"url":"https://api.github.com/repos/m-kuhn/QGIS","forks_url":"https://api.github.com/repos/m-kuhn/QGIS/forks","keys_url":"https://api.github.com/repos/m-kuhn/QGIS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m-kuhn/QGIS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m-kuhn/QGIS/teams","hooks_url":"https://api.github.com/repos/m-kuhn/QGIS/hooks","issue_events_url":"https://api.github.com/repos/m-kuhn/QGIS/issues/events{/number}","events_url":"https://api.github.com/repos/m-kuhn/QGIS/events","assignees_url":"https://api.github.com/repos/m-kuhn/QGIS/assignees{/user}","branches_url":"https://api.github.com/repos/m-kuhn/QGIS/branches{/branch}","tags_url":"https://api.github.com/repos/m-kuhn/QGIS/tags","blobs_url":"https://api.github.com/repos/m-kuhn/QGIS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m-kuhn/QGIS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m-kuhn/QGIS/git/refs{/sha}","trees_url":"https://api.github.com/repos/m-kuhn/QGIS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m-kuhn/QGIS/statuses/{sha}","languages_url":"https://api.github.com/repos/m-kuhn/QGIS/languages","stargazers_url":"https://api.github.com/repos/m-kuhn/QGIS/stargazers","contributors_url":"https://api.github.com/repos/m-kuhn/QGIS/contributors","subscribers_url":"https://api.github.com/repos/m-kuhn/QGIS/subscribers","subscription_url":"https://api.github.com/repos/m-kuhn/QGIS/subscription","commits_url":"https://api.github.com/repos/m-kuhn/QGIS/commits{/sha}","git_commits_url":"https://api.github.com/repos/m-kuhn/QGIS/git/commits{/sha}","comments_url":"https://api.github.com/repos/m-kuhn/QGIS/comments{/number}","issue_comment_url":"https://api.github.com/repos/m-kuhn/QGIS/issues/comments{/number}","contents_url":"https://api.github.com/repos/m-kuhn/QGIS/contents/{+path}","compare_url":"https://api.github.com/repos/m-kuhn/QGIS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m-kuhn/QGIS/merges","archive_url":"https://api.github.com/repos/m-kuhn/QGIS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m-kuhn/QGIS/downloads","issues_url":"https://api.github.com/repos/m-kuhn/QGIS/issues{/number}","pulls_url":"https://api.github.com/repos/m-kuhn/QGIS/pulls{/number}","milestones_url":"https://api.github.com/repos/m-kuhn/QGIS/milestones{/number}","notifications_url":"https://api.github.com/repos/m-kuhn/QGIS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m-kuhn/QGIS/labels{/name}","releases_url":"https://api.github.com/repos/m-kuhn/QGIS/releases{/id}","deployments_url":"https://api.github.com/repos/m-kuhn/QGIS/deployments","created_at":"2012-08-02T09:19:28Z","updated_at":"2018-06-21T10:11:36Z","pushed_at":"2018-06-26T11:01:12Z","git_url":"git://github.com/m-kuhn/QGIS.git","ssh_url":"git@github.com:m-kuhn/QGIS.git","clone_url":"https://github.com/m-kuhn/QGIS.git","svn_url":"https://github.com/m-kuhn/QGIS","homepage":"http://qgis.org","size":1376010,"stargazers_count":5,"watchers_count":5,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":22,"license":{"key":"gpl-2.0","name":"GNU General Public License v2.0","spdx_id":"GPL-2.0","url":"https://api.github.com/licenses/gpl-2.0","node_id":"MDc6TGljZW5zZTg="},"forks":1,"open_issues":22,"watchers":5,"default_branch":"master"}},"base":{"label":"qgis:master","ref":"master","sha":"d7b85c69f8b3cbffb1261d133cb98bec38392927","user":{"login":"qgis","id":483444,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ4MzQ0NA==","avatar_url":"https://avatars3.githubusercontent.com/u/483444?v=4","gravatar_id":"","url":"https://api.github.com/users/qgis","html_url":"https://github.com/qgis","followers_url":"https://api.github.com/users/qgis/followers","following_url":"https://api.github.com/users/qgis/following{/other_user}","gists_url":"https://api.github.com/users/qgis/gists{/gist_id}","starred_url":"https://api.github.com/users/qgis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qgis/subscriptions","organizations_url":"https://api.github.com/users/qgis/orgs","repos_url":"https://api.github.com/users/qgis/repos","events_url":"https://api.github.com/users/qgis/events{/privacy}","received_events_url":"https://api.github.com/users/qgis/received_events","type":"Organization","site_admin":false},"repo":{"id":1690480,"node_id":"MDEwOlJlcG9zaXRvcnkxNjkwNDgw","name":"QGIS","full_name":"qgis/QGIS","owner":{"login":"qgis","id":483444,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ4MzQ0NA==","avatar_url":"https://avatars3.githubusercontent.com/u/483444?v=4","gravatar_id":"","url":"https://api.github.com/users/qgis","html_url":"https://github.com/qgis","followers_url":"https://api.github.com/users/qgis/followers","following_url":"https://api.github.com/users/qgis/following{/other_user}","gists_url":"https://api.github.com/users/qgis/gists{/gist_id}","starred_url":"https://api.github.com/users/qgis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qgis/subscriptions","organizations_url":"https://api.github.com/users/qgis/orgs","repos_url":"https://api.github.com/users/qgis/repos","events_url":"https://api.github.com/users/qgis/events{/privacy}","received_events_url":"https://api.github.com/users/qgis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/qgis/QGIS","description":"QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)","fork":false,"url":"https://api.github.com/repos/qgis/QGIS","forks_url":"https://api.github.com/repos/qgis/QGIS/forks","keys_url":"https://api.github.com/repos/qgis/QGIS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/qgis/QGIS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/qgis/QGIS/teams","hooks_url":"https://api.github.com/repos/qgis/QGIS/hooks","issue_events_url":"https://api.github.com/repos/qgis/QGIS/issues/events{/number}","events_url":"https://api.github.com/repos/qgis/QGIS/events","assignees_url":"https://api.github.com/repos/qgis/QGIS/assignees{/user}","branches_url":"https://api.github.com/repos/qgis/QGIS/branches{/branch}","tags_url":"https://api.github.com/repos/qgis/QGIS/tags","blobs_url":"https://api.github.com/repos/qgis/QGIS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/qgis/QGIS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/qgis/QGIS/git/refs{/sha}","trees_url":"https://api.github.com/repos/qgis/QGIS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/qgis/QGIS/statuses/{sha}","languages_url":"https://api.github.com/repos/qgis/QGIS/languages","stargazers_url":"https://api.github.com/repos/qgis/QGIS/stargazers","contributors_url":"https://api.github.com/repos/qgis/QGIS/contributors","subscribers_url":"https://api.github.com/repos/qgis/QGIS/subscribers","subscription_url":"https://api.github.com/repos/qgis/QGIS/subscription","commits_url":"https://api.github.com/repos/qgis/QGIS/commits{/sha}","git_commits_url":"https://api.github.com/repos/qgis/QGIS/git/commits{/sha}","comments_url":"https://api.github.com/repos/qgis/QGIS/comments{/number}","issue_comment_url":"https://api.github.com/repos/qgis/QGIS/issues/comments{/number}","contents_url":"https://api.github.com/repos/qgis/QGIS/contents/{+path}","compare_url":"https://api.github.com/repos/qgis/QGIS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/qgis/QGIS/merges","archive_url":"https://api.github.com/repos/qgis/QGIS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/qgis/QGIS/downloads","issues_url":"https://api.github.com/repos/qgis/QGIS/issues{/number}","pulls_url":"https://api.github.com/repos/qgis/QGIS/pulls{/number}","milestones_url":"https://api.github.com/repos/qgis/QGIS/milestones{/number}","notifications_url":"https://api.github.com/repos/qgis/QGIS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/qgis/QGIS/labels{/name}","releases_url":"https://api.github.com/repos/qgis/QGIS/releases{/id}","deployments_url":"https://api.github.com/repos/qgis/QGIS/deployments","created_at":"2011-05-02T08:06:26Z","updated_at":"2018-06-26T11:01:18Z","pushed_at":"2018-06-26T13:13:39Z","git_url":"git://github.com/qgis/QGIS.git","ssh_url":"git@github.com:qgis/QGIS.git","clone_url":"https://github.com/qgis/QGIS.git","svn_url":"https://github.com/qgis/QGIS","homepage":"http://qgis.org","size":1441104,"stargazers_count":2087,"watchers_count":2087,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1263,"mirror_url":null,"archived":false,"open_issues_count":32,"license":{"key":"gpl-2.0","name":"GNU General Public License v2.0","spdx_id":"GPL-2.0","url":"https://api.github.com/licenses/gpl-2.0","node_id":"MDc6TGljZW5zZTg="},"forks":1263,"open_issues":32,"watchers":2087,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/qgis/QGIS/pulls/7315"},"html":{"href":"https://github.com/qgis/QGIS/pull/7315"},"issue":{"href":"https://api.github.com/repos/qgis/QGIS/issues/7315"},"comments":{"href":"https://api.github.com/repos/qgis/QGIS/issues/7315/comments"},"review_comments":{"href":"https://api.github.com/repos/qgis/QGIS/pulls/7315/comments"},"review_comment":{"href":"https://api.github.com/repos/qgis/QGIS/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/qgis/QGIS/pulls/7315/commits"},"statuses":{"href":"https://api.github.com/repos/qgis/QGIS/statuses/833c4221d41e1bc4d4bb8ece05882d19ef943a7e"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"m-kuhn"}}