Selection - insert with StaticConvetions spoils PDO::lastInsertId
Stopka opened this issue · 1 comments
Version: >2.4
Bug Description
When using StaticConvetions, Selection::insert of one row on first trial doesn't return ActiveRow of new inserted row. It is because Structure cache is built on demand of getPrimarySequence getPrimaryAutoincrementKey which is called after insert query. And building the cache means another database query, which spoils PDO::lastInsertId.
I found older, still not solved reference for this problem here https://forum.nette.org/cs/27506-insert-pri-reflection-conventional-nevraci-activerow
Steps To Reproduce
Use StaticConvetions, empty Structure cache and try to insert one row into table (with autoincrement pk).
Expected Behavior
Insert should return inserted row in form of ActiveRow, but it doesn't
Possible Solution
One simple solution would be changing the order of method calls, so that getPrimarySequence and getPrimaryAutoincrementKey are called before actual query. Can prepare PR.
PR is welcome, thanks!