We have the following use case:
A node type with a multi-value entityreference field that references users.
The users listed on a node are the ones responsible for the node, so they all should have update permissions on the node.
We use standard drupal node access for that.
View access to the node type is arranged on role level.
On creation of a node with duplicate entries in the list of responsible users we get the following PDOException:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '7970-3-responsible' for key 'PRIMARY': INSERT INTO {node_access} (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5), (:db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11); Array#012(#012 [:db_insert_placeholder_0] => 7970#012 [:db_insert_placeholder_1] => responsible#012 [:db_insert_placeholder_2] => 3#012 [:db_insert_placeholder_3] => 0#012 [:db_insert_placeholder_4] => 1#012 [:db_insert_placeholder_5] => 0#012 [:db_insert_placeholder_6] => 7970#012 [:db_insert_placeholder_7] => responsible#012 [:db_insert_placeholder_8] => 3#012 [:db_insert_placeholder_9] => 0#012 [:db_insert_placeholder_10] => 1#012 [:db_insert_placeholder_11] => 0#012)
We wrote a small patch on entityreference_field_validate that throws an error if a duplicate is detected.
So we left it up to the user to resolve the conflict.
The other option would be to resolve it automatically.
We leave this to the maintainers of this module.
Comment | File | Size | Author |
---|---|---|---|
entityreference-duplicate-entries.patch | 954 bytes | Jan van Diepen | |
Comments
Comment #1
amitaibuSorry, I don't understand how you gor the duplicate errors. Do you have steps to reproduce?
Comment #2
Jan van Diepen CreditAttribution: Jan van Diepen commentedWe just reference the same user twice on a multi-value entityreference field. Entityreference will try to add the same user twice which will lead to the 1062 Duplicate entry PDOException. The patch on form_validate will display an error message on submission of the form. To automate this any duplicate references should be removed before actual submission.
Comment #3
regedite CreditAttribution: regedite commentedentityreference-duplicate-entries.patch queued for re-testing.
Comment #4
Rob_Feature CreditAttribution: Rob_Feature commentedI'm actually seeing this same error, but for the file_managed table while running a drush function (drush geocoder-backfill). I'm not sure how it's related, but wanted to chime in that I'm seeing it too....