Problem

  1. Merge::key() accepts an associative array possibly containing multiple values.
  2. Merge::fields(), Merge::values(), etc are all plural.
  3. But yet, Merge::key() is singular.

Proposed solution

  1. Rename the method into Merge::keys(), but provide a backwards-compatible alias Merge::key().

Comments

sun’s picture

Title: Rename Database\Query\Merge::key() to keys(), or at least provide an alias » Rename Database\Query\Merge::key() to keys(), retain a BC alias for key()
jibran’s picture

Status: Needs review » Reviewed & tested by the community

simple enough.

Crell’s picture

The typical case for a merge query is a single-value key; multi-value keys are not common IME. That's why it was called key() originally. If we do this, I would not mark key() deprecated. Just call it an alias and be done with it.

sun’s picture

StatusFileSize
new1.03 KB

Happy to do so :-)


That said, given the explanation for why the method is using a singular name (thanks!), I wondered whether this split here wouldn't actually allow us to give key() a signature that corresponds to its intended use-case?

Like this:

  public function key($field, $value) {
    $this->keys(array($field => $value));
    return $this;
  }

Might be worth as a follow-up issue?

Crell’s picture

Status: Reviewed & tested by the community » Needs work

Good idea. Let's go ahead and do that now. So keys() takes a single associative array, key() takes a singluar key and value. That's more descriptive and non-redundant. And I think not even an API change. :-)

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new20.31 KB
new20.21 KB
  1. Changed signature of Merge::key(), but retaining a BC shim.
  2. Converted all Merge queries to either use keys(array) or key(field, value).

The last submitted patch, 4: drupal8.db-merge-key.4.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 6: merge.keys_.6.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new20.18 KB
new1.01 KB

Reverted change to invocation order in Cache\DatabaseBackend.

This should come back green again now.

sun’s picture

Draft change notice: https://drupal.org/node/2205327

sun’s picture

9: merge.keys_.9.patch queued for re-testing.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Done and done. Thanks, sun.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Nice little API improvement. Committed to 8.x.

Status: Fixed » Closed (fixed)

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