This results in the blank object being hydrated with data from the first row in the db.
This seems wrong. Blank objects should not be considered to exist.
/**
* Shortcut method which will determine whether a row
* with the current instances properties exists. If so, it will
* preload those values (side effects).
*
* Usage:
* $model->id = 1;
* if($model->exists()) {
* die('a lonesome death');
* }
*
* @return boolean
*/
function exists() {}Here's how Model::exists() used to behave.
$user = new User(); echo ( $user->exists() ? $user->id : 0 );
1
Here's how it behaves now
$user = new User(); echo ( $user->exists() ? $user->id : 0 );
0
If there are no model column properties set, Model::exists() returns false.
Old code:
function exists() {
$result = $this->select()->first();
if($result !== false) {
$this->copy($result, false);
return true;
} else {
return false;
}
}New code:
function exists() {
$descriptor = self::getClassDescriptor($this);
$blank_object = true;
foreach($this as $column => $value) {
if(in_array($column, $descriptor->columns) && isset($value)) {
$blank_object = false;
}
}
if(!$blank_object) {
$result = $this->select()->first();
if($result !== false) {
$this->copy($result, false);
return true;
} else {
return false;
}
} else {
return false;
}
}Logically it's the diff between
... WHERE 1 [&& (...)] ... WHERE 0 [|| (...)]
Kris, have you considered this use case?
Do you agree with my assessment?

Sign In
Register
Help

MultiQuote