-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
QBMapper id doesn't have to be an int #16944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Found when looking at nextcloud/mail#1969 Signed-off-by: Roeland Jago Douma <[email protected]>
f9c8332 to
cb5464a
Compare
|
server/lib/public/AppFramework/Db/QBMapper.php Lines 123 to 125 in 5aeb8ea
If someone uses a string as id the value is already set before insert. So id is not null and getLastInsertId() is not called. |
|
Ah mmm right... meh. let me think some moreabout it then. |
|
Sorry 🙈 Let me rephrase it: I don't think we have to care about the case because its unlikely. If someone use a hash as id the hash should be set before the insert. We could throw a exception if the type is not integer and the id is null. |
|
|
||
| $qb->where( | ||
| $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) | ||
| $qb->expr()->eq('id', $qb->createNamedParameter($id, $this->getParameterTypeForProperty($entity, 'id'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was also my consideration. The only problem with this is the default type. It should be a new optional parameter with string as default and overwritten in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, id has a default type of integer set. so this should actually work then
See mail. This happens when you try to run an
|
|
Sorry for the confusion 🙈 server/lib/public/AppFramework/Db/QBMapper.php Lines 123 to 125 in 5aeb8ea
For entities without id the lastInsertId is set as id. A entity with
I was wondering if we need to care about this edge case. If someone complains we can still fix it later. I think for the mail app you usually try to insert entities with ids. |
|
Yep, lastInsertId is indeed a problem the way it's used here.
So the problem is actually inserting a row without an |
You may interested in this former discussion: #13086 |
|
Ok maybe this isn't the most elegant way... let me consider a different approach later this evening. |
Found when looking at nextcloud/mail#1969
Signed-off-by: Roeland Jago Douma [email protected]