Skip to content

Commit

Permalink
refactor: use COALESCE in having condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Waldstein committed Nov 27, 2023
1 parent c719922 commit b518edf
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/Donations/Endpoints/ListDonations.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,7 @@ private function getWhereConditions(QueryBuilder $query): array
}

if ($hasWhereConditions) {
if ($testMode){
$query->having(
'give_donationmeta_attach_meta_mode.meta_value',
'=',
DonationMode::TEST
);
}
$query->havingRaw('HAVING COALESCE(give_donationmeta_attach_meta_mode.meta_value, %s) = %s', DonationMode::LIVE, $testMode ? DonationMode::TEST : DonationMode::LIVE);

This comment has been minimized.

Copy link
@JasonTheAdams

JasonTheAdams Nov 27, 2023

Contributor

@jonwaldstein havingRaw should still handle adding the HAVING keyword, otherwise it risks breaking chaining.

This comment has been minimized.

Copy link
@jonwaldstein

jonwaldstein Nov 27, 2023

Contributor

It looks like @alaca updated this method last year to exclude the HAVING keyword.
57f19c3

Changing this api is not something I would want to do here as it's a separate concern.

This comment has been minimized.

Copy link
@JasonTheAdams

JasonTheAdams Nov 27, 2023

Contributor

@alaca Can we please fix this? Chaining $query->having and $query->havingRaw should work. The idea of it being raw should provide control over the condition, not the presence of the HAVING keyword.

This comment has been minimized.

Copy link
@alaca

alaca Nov 28, 2023

Member

@JasonTheAdams sure, no problem.

} elseif ($testMode) {
$query->where('give_donationmeta_attach_meta_mode.meta_value', DonationMode::TEST);
} else {
Expand Down

0 comments on commit b518edf

Please sign in to comment.