Skip to content

Commit

Permalink
Disambiguate Address.state_province_id:abbr (MySQL; simpler version)
Browse files Browse the repository at this point in the history
Consider `ContactJoinTest::testCreateWithPrimaryAndBilling` which writes the value:

  'address_billing.state_province_id:abbr' => 'AK',

The symbol 'AK' can map to three places: Akwa Ibom (Nigeria), Atakora
(Benin), and Alaska (USA).  This is an ambiguous choice.  It should be
resolved in a consistent way.

One flavor of ambiguity comes from MySQL.  When loading abbreviations, Civi
queries with `ORDER BY abbreviation`.  This is a *typically* stable, but it
has no *guaranteed* resolution.  Adding a secondary sort key makes the
outcome clear/unambiguous.
  • Loading branch information
totten committed Feb 10, 2023
1 parent dc63465 commit 8979ac6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CRM/Core/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,8 @@ public static function renderOptionsFromTablePseudoconstant($pseudoconstant, &$p
$select = 'SELECT %1 AS id, %2 AS label';
$from = 'FROM %3';
$wheres = [];
$order = 'ORDER BY %2';
$order = 'ORDER BY %2, id';
// Example: 'ORDER BY abbreviation, id' because abbreviations are not unique.

// Use machine name in certain contexts
if ($context === 'validate' || $context === 'match') {
Expand Down

0 comments on commit 8979ac6

Please sign in to comment.