Fix for empty primary keys in create method #45

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@hkdobrev

The create method will check if the primary key is set, but will not check whether it is empty. The ORM should not allow empty primary keys. I have added a check against empty primary key.

@kemo kemo commented on the diff Apr 10, 2014
classes/kohana/orm.php
@@ -1221,7 +1221,7 @@ public function create(Validation $validation = NULL)
->values(array_values($data))
->execute($this->_db);
- if ( ! array_key_exists($this->_primary_key, $data))
+ if ( ! array_key_exists($this->_primary_key, $data) && ! empty($data[$this->_primary_key]) )
@kemo
kemo Apr 10, 2014

Use AND instead of &&

@kemo
kemo Apr 10, 2014

This condition will never be true?

@kemo
Kohana PHP Framework member

Closing as the "adjusted" condition in this pull request will never be true as far as I can tell. Let me know if you think otherwise and I will reopen this.

@kemo kemo closed this Apr 10, 2014
@hkdobrev hkdobrev deleted the unknown repository branch May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment