Repository navigation
Fix multi-line insert return type - #330
Merged
Merged
Conversation
Member
|
Thanks |
dg
pushed a commit
that referenced
this pull request
Jun 7, 2026
dg
pushed a commit
that referenced
this pull request
Jun 7, 2026
dg
pushed a commit
that referenced
this pull request
Jun 8, 2026
dg
pushed a commit
that referenced
this pull request
Jul 16, 2026
dg
pushed a commit
that referenced
this pull request
Jul 16, 2026
dg
pushed a commit
that referenced
this pull request
Jul 16, 2026
dg
pushed a commit
that referenced
this pull request
Jul 16, 2026
dg
added a commit
that referenced
this pull request
Jul 16, 2026
… multi-insert (#330) Multi-line inserting wasn't returning the number of affected rows but an ActiveRow instead (with the first inserted record). The documented behaviour is: a single associative array inserts one row and returns the ActiveRow, a list of rows or a Selection performs a bulk insert and returns the count. A list is recognized by its keys being integers - they need not be sequential, since a filtered array leaves gaps in them, and an integer is never a column name. Such rows are reindexed before the query. Rows coming from a Traversable are drained by position, so none is lost when a generator yields them under colliding keys (`yield from`). An empty array stays a single insert of database defaults, so an unfilled form ($form->getValues()) still inserts a row. Both checks live in Helpers::materializeRows() and Helpers::isRowList(), so that insert() and GroupedSelection share one notion of what a list of rows is. forum thread: https://forum.nette.org/cs/36954-nette-database-v3-2-9-phpdoc-selection-insert-nepokryva-dokumentovany-bulk-insert Co-authored-by: Matěj Kmínek <m@kminet.eu>
dg
added a commit
that referenced
this pull request
Aug 27, 2026
… multi-insert (#330) Multi-line inserting wasn't returning the number of affected rows but an ActiveRow instead (with the first inserted record). The documented behaviour is: a single associative array inserts one row and returns the ActiveRow, a list of rows or a Selection performs a bulk insert and returns the count. A list is recognized by its keys being integers - they need not be sequential, since a filtered array leaves gaps in them, and an integer is never a column name. Such rows are reindexed before the query. Rows coming from a Traversable are drained by position, so none is lost when a generator yields them under colliding keys (`yield from`). An empty array stays a single insert of database defaults, so an unfilled form ($form->getValues()) still inserts a row. Both checks live in Helpers::materializeRows() and Helpers::isRowList(), so that insert() and GroupedSelection share one notion of what a list of rows is. forum thread: https://forum.nette.org/cs/36954-nette-database-v3-2-9-phpdoc-selection-insert-nepokryva-dokumentovany-bulk-insert Co-authored-by: Matěj Kmínek <m@kminet.eu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Multi-line inserting wasnt returning numeric number of affected rows but ActiveRow instead (with first inserted record).
This fix checks if the
$datainserted is actually a two-dimensional array and if so, returns number of affected rows instead of the ActiveRow.Tests were added as well since this path was not guarded