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)


on 06.24.10 reported by: michaelhue owned by: Howard

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
This has been fixed in the x-relationships branch: http://dev.lithify.me/lithium/commits/view/747b3b6372630c84986b258cb0e789b3e4ff7034