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

Skip to content

Conversation

@mabar
Copy link
Contributor

@mabar mabar commented Oct 25, 2025

DbalCollection::getBy* (and inherently Repository::getBy*) methods apply LIMIT 1

  • As a performance optimalization for columns that are not defined as UNIQUE.
  • In case the query returned multiple records before, only first record was used and other were just thrown away.
  • I have not made any changes to ArrayCollection because it is short-lived in this case and no such change was necessary.
  • It is disabled for mssql, because it fails on invalid syntax (Incorrect syntax near 'OFFSET'.). I believe this should be handled in nextras/dbal?
  • It can be turned off via Nextras\Orm\FeatureToggle::$limitInGetBy = false; in case it causes any issues. This toggle is planned to be removed in v6.

Build changes (that made my life easier):

  • switched Docker PHP image from Alpine to Debian because I was not able to make mssql work with Alpine
  • added mssql to Docker (to be able to test it)
    • it is neccessary to accept their EULA to make the builds work, let me know if I should make the mssql part optional
  • GitHub Actions builds run on all branches (and cancel duplicates in case PR exists in the same repository)
    • it is more convenient than getting notifications about WIP commits
  • default PostgreSQL version in Docker is set to 17, v18 builds are broken

Copy link
Member

@hrach hrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, two little things please

{
return $this->findBy($conds)->fetch();
$collection = $this->findBy($conds);
if (FeatureToggle::$limitInGetBy && $this->connection->getPlatform()->getName() !== SqlServerPlatform::NAME) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition on sql platform needs a comment/reasoning.

Copy link
Contributor Author

@mabar mabar Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment about invalid syntax being generated.

SqlServer might also be supported in theory, but I was not able to do the necessary changes in QueryBuilder - there are more ways how to do it and none of them seems to behave the same as MySQL and PostgreSQL.
I'd suggest to add generated sql files to tests for MySQL and SqlServer before we do so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry to bother you once more, but the comment does not add any value - I already knew that you had tried it because it doesn't work. It would be great to add a meaningful example of what does not work or create a ticket and put it there, and put the link into the code... :)

Seeing the wrong SQL it generates everybody exploring the source code will be to "I see, now I understand why it behaves differently" :)

@mabar mabar requested a review from hrach October 26, 2025 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants