Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dereuromark
Copy link
Member

@dereuromark dereuromark commented Oct 17, 2025

Re-implements old 3.x way of
dereuromark/cakephp-shim@2cade8d

Supported Pattern

  // Association field
  $query = $this->Posts->find()
      ->contain(['Authors'])
      ->select(['Authors.name']);
  $result = $query->find('list')->toArray();
  // Result: ['mariano' => 'mariano', 'larry' => 'larry', ...]

  // Main table field
  $query = $this->Articles->find()
      ->select(['title'])
      ->disableAutoFields();
  $result = $query->find('list')->toArray();
  // Result: ['First Article' => 'First Article', ...]

Also:

  • When 2 fields are given in select(), it also automatically uses them (again) for key and value.

This avoids having to verbosely set the key and value fields, while it is clear with a single (or 2) select value that those are meant for both key and value.

Resolves an annoying regression that was there after upgrading apps to 4.x/5.x

Since this only affects those that didnt declare them manually and have less than 2 fields, this should not affect people, so should be fully BC in that way.

@dereuromark dereuromark added this to the 5.2.9 milestone Oct 17, 2025
@ADmad
Copy link
Member

ADmad commented Oct 17, 2025

I don't like this change, it re-adds a lot of code to reimplement an implicit feature.

This could be instead re-added to the Shim plugin as the method can be easily overridden at the app/plugin level.

@dereuromark
Copy link
Member Author

It is already in Shim plugin, and I am happy to keep it there for my use and easier work with find(list).

Just thought maybe, since it doesnt affect anyone not "affected" by it, it could be a valuable ease for developers around simple find(list) calls with 1 or 2 fields in select.
And would not harm anyone else.

If the consensus is to keep it in Shim, feel free to close.

@dereuromark dereuromark requested a review from markstory October 23, 2025 03:40
@dereuromark dereuromark changed the title Fix up regression on find(list) again for 5.next. Fix up regression on find(list) again for 5.x Oct 23, 2025
@markstory markstory modified the milestones: 5.2.9, 5.2.10 Oct 24, 2025
@LordSimal
Copy link
Contributor

I am also against adding this back.

@dereuromark dereuromark deleted the 5.next-find-list branch October 28, 2025 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants