I think #2615078: Create unique constraint on {election_ballot} needs reverting... unfortunately I'm still gradually remembering the decisions I made a long time ago.

There are two problems with the unique constraint on ( post_id, uid ) on the {election_ballot} table:

  1. Anonymous users can vote and currently their UID is always 0 (I started working on this in #2627414: Bypass unique constraint for anonymous users).
  2. Users are allowed to have multiple election_ballot records if they "undo" their vote. Undoing sets the ballot's value to 0, and thereafter the user can vote again. This is a valuable feature, and it's also very valuable that the database record is simply updated with value=0 rather than being deleted - it provides an audit trail of each time the user voted.
CommentFileSizeAuthor
#2 election-2627710-2.patch1.65 KBpjcdawkins

Comments

pjcdawkins created an issue. See original summary.

pjcdawkins’s picture

StatusFileSize
new1.65 KB
pjcdawkins’s picture

pjcdawkins’s picture

liam morland’s picture

Adding a comment on the election_ballot table explaining this would be helpful. This relates to #2621482: Document NULLs in schema.

  • pjcdawkins committed 79fb513 on 7.x-1.x
    Issue #2627710: Revert unique constraint on {election_ballot}
    
pjcdawkins’s picture

Status: Needs review » Active

Committed, with a huge comment explaining this next to the 'uid' field, so it's now at least not broken.

So... next I would like to refactor ballot saving and loading - adding new function(s), which should make this clearer.

pjcdawkins’s picture

Status: Active » Fixed
liam morland’s picture

It would also be helpful to document in more detail what the 'value' column means. It says that zero means the vote will not be counted, but what other values are allowed and what do they mean?

pjcdawkins’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.