Bug Report #3817
_primary_key_value not set when pk value is supplied
|Assignee:||Lorenzo Pisani||% Done:|
|Target version:||Kohana v3.x - v3.1.4|
I have an Item model with a primary key which is not autoincrement, but it's instead supplied before saving.
I create the model, fill in the fields (pk included), then save().
Kohana_ORM->create() checks if $data[_primary_key] is set before setting both _object[_primary_key] and _primary_key_value, and since it's already set (because the pk value was manually set before save()), _primary_key_value remains NULL. (source:/classes/kohana/orm.php@af3137ed#L1283)
The Item model is left unusable:
Later, I have to add the Item as a _belongs_to relationship to a Detail model.
The Detail model fails to save(), because the non-nullable field `item_id` is filled with $item->pk(), which is NULL.
I believe _object[_primary_key] and _primary_key_value should be set separately, with _primary_key_value always being updated if it's empty, regardless of the status of $data[_primary_key].
#6 Updated by Martino di Filippo over 2 years ago
I don't know why it has decided to close this bug report automatically, I didn't do it.
I just issued a pull request, which is here: https://github.com/kohana/orm/pull/37
Also, I didn't know which branch to push to, so I created a 3817-patch branch.
You should decide where to merge it eventually :)
#7 Updated by Lorenzo Pisani over 2 years ago
- Status changed from Closed to Assigned
- Assignee set to Lorenzo Pisani
- % Done changed from 100 to 0
Very weird... it looks like GitHub shows all the commits from pull requests as well. Which means Redmine got that commit and thought it was in the main repo, which closed the ticket based on the commit message. Quite awkward. In the future, let's try to use "refs #1234" when you are supplying a fix, the main devs can then use the "fixes..." commit message in their merge commit. That should list everything nicely here.
Thanks for the pull request, I'll make sure this is pulled in as soon as possible.
#8 Updated by Lorenzo Pisani over 2 years ago
A little further explanation... this is what happened:
See, you can find your commit in the official kohana/orm repo, although it hasn't been pulled into a branch yet. Redmine found this commit, read the message that said it was a fix for this ticket, and closed the ticket. We probably have to document this somewhere in the docs so it doesn't happen again. No pull requests should ever include the "fixes..." command, just "refs..."
At least that's what I think happened.
#11 Updated by Lorenzo Pisani over 2 years ago
- Status changed from Assigned to Closed
- Resolution set to fixed