Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Can we 'removeWhere' #203

Open
eileenmcnaughton opened this issue Oct 9, 2019 · 1 comment
Open

Can we 'removeWhere' #203

eileenmcnaughton opened this issue Oct 9, 2019 · 1 comment

Comments

@eileenmcnaughton
Copy link
Contributor

I'm just looking at this code

https://github.com/civicrm/civicrm-core/pull/15456/files#diff-eba7056035c65245b5dd9bf4ccac8fe4R437

Which does 2 api calls with the same parameters except one less the second time - a 'removeWhere' would make it shorter....

@colemanw @totten any ideas on nice ways here?

@colemanw
Copy link
Member

@eileenmcnaughton I'm not a big fan of that; I'm worried that removeWhere would get confused with addWhere('NOT', ...) which is a thing. Technically you can setWhere to a different value, so maybe the most readable version of this code would be:

    $contributionWhereClause = [
      ['contribution_recur_id', '=', $id],
      ['is_test', '=', $is_test],
    ];
    $contributionApi = \Civi\Api4\Contribution::get()
      ->setWhere($contributionWhereClause)
      ->addWhere('is_template', '=', 1)
      ->addOrderBy('id', 'DESC')
      ->setLimit(1);
    // First look for new-style template contribution with is_template=1
    $templateContributions = $contributionApi->execute();
    if (!$templateContributions->count()) {
      // Fall back to old style template contributions without is_template
      $templateContributions = $contributionApi->setWhere($contributionWhereClause)->execute();
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants