-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/event#66: allow duplicate price field labels #22508
dev/event#66: allow duplicate price field labels #22508
Conversation
(Standard links)
|
Thanks @twomice :-) |
I see there's general support for this change in the community. I don't love the idea of duplicate names in a table, but I note that the deleted code wasn't actually preventing that (not reliably anyway), so it's not a blocker. |
I agree label shouldn't be unique but I think having it be unique is making name pseudo-unique and there are all sorts of ways we expect name to be unique I think I feel like we are setting ourselves up for problems down the track if we don't enforce name to be unique now - in future we have talked about the possibility of being able to mix and match price fields from different price sets - so even unique within a price set will still be tricky later on I think |
Hi @eileenmcnaughton In "writing" this PR I did think at first that I'd like to emulate some other entities that are (as @colemanw pointed out in the ticket) appending an integer to non-unique |
I don't think there's a good, tested, generic function to do that. But there should be. Here's an example of an ad-hoc solution in a single BAO. Let me see if I can turn it into something reusable. civicrm-core/CRM/Contact/BAO/SavedSearch.php Lines 345 to 357 in ddc4b6b
|
OK @twomice I've refactored the above into a centralized function that's smart enough to use db indices to consider what combination of fields constitutes a "unique" name: #22570 Unfortunately that index doesn't exist (yet) on the entity. IMO the correctest fix is to:
Since it already uses |
@colemanw I think we should make |
I'm also inclined to think that |
Would like to make a comment:
So what I'm getting at is in situation 3 name could be any random string and doesn't have to be related to label, and in fact that would help with confusion of name vs label, and make it easier to make it unique. |
@demeritcowboy I appreciate that name can be anything, but I don't see a strong reason to break our pattern of deriving |
Ok. Just wanted to make the comment about what |
I just merged the other - is this now mergeable @colemanw ? I think it will enforce a unique name - although I think we should have riffed on the above commentary & used random star trek terms as our new naming convention |
Make it sew..... |
So yes, this is mergeable (merged in fact) but it's not actually going to enforce a unique name because there's no unique index on that column. To fully sew up this issue, we'd need to:
|
@colemanw did ^^ get done ? I guess if not we might have a window where people are making it sorta worse but the update script would still address |
Overview
Reference ticket: https://lab.civicrm.org/dev/event/-/issues/66
Community discussion in that ticket indicates it would be desirable to allow two price fields to have the same label, which is currently prevented by CiviCRM. This PR removes that restriction, allowing two price fields to have the same label.
Before
If a price field labeled "Test" already exists, user will receive a form validation error when trying to create a second price field in that price set with label "Test".
After
If a price field labeled "Test" already exists, user will NOT receive a form validation error when trying to create a second price field in that price set with label "Test"; instead, the price field is simply created.
Technical Details
This PR simply removes the form validation rule that was enforcing unique field labels. In the OP ticket, someone mentioned that other civicrm entities append an integer to the
name
column value wherename
is not unique, but no attempt was made to emulate that behavior. (In a quick scan of the code and some trial-and-error, I was unable to find any entities that do that, and I'm convinced, along with other commenters in that ticket, that failure to enforce a uniquename
column is not going to cause problems, as there are many entities which do not enforce that requirement.)Comments
Thanks to DaveD for pointing out the code block referenced in this PR.