Ticket Details
Unexpected behavior when restricting fields in a Model::find() operation (MySQL)
BUG Ticket (closed)
###What happened:
When restricting a ```Model::find()``` operation to only one field (MySQL), an array is returned.
{{{
$user = User::find('first', array(
'conditions' => array('id' => 1),
'fields' => array('id')
));
var_dump($user);
// array
// 0 => string '1' (length=1)
}}}
The second problem is that running a model method on an entity that doesn't contain all of the models fields results in an exception.
{{{
// 1. Record with all fields
$user1 = User::find('first', array('conditions' => array('id' => 1)));
$user1->save();
// ok
// 2. Record with restricted fields
$user2 = User::find('first', array('conditions' => array('id' => 1), 'fields' => array('id', 'name', 'email'));
$user2->save();
// RuntimeException: No model bound or unhandled method call 'save'. in /Users/Micha/Sites/lib/lithium_fork/libraries/lithium/data/Entity.php on line 180
}}}
###Test Case:
I created an integration test for both issues:
[http://pastium.org/view/ddffb82fbf10bd6dab9ff05f18fea10b](http://pastium.org/view/ddffb82fbf10bd6dab9ff05f18fea10b)
Updates
on 03.02.11
by nate
- owner was changed to Howard
(fixed)
on 03.03.11
by Howard
- status was changed to closed
- resolution was changed to fixed