Skip to content

Commit

Permalink
handle empty property names in marshalValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared King committed Jan 13, 2015
1 parent 1b50378 commit 872b3a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,6 @@ public function create(array $data = [])
*/
public function get($properties, $skipLocalCache = false, $forceReturnArray = false)
{
$show = $properties == 'relation';
if (is_string($properties)) {
$properties = explode(',', $properties);
} else {
Expand Down Expand Up @@ -1409,6 +1408,10 @@ private function checkUniqueness($property, $field, $value)

private function marshalValue($property, $value)
{
if (empty($property)) {
return $value;
}

// look up property (if it exists)
$pData = static::properties($property);
if (!$pData) {
Expand Down
12 changes: 12 additions & 0 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,20 @@ public function testGetDefaultValue()
$this->assertEquals('some default value', $model->get('default'));
}

public function testGetEmptyProperty()
{
self::$app['db'] = Mockery::mock();
self::$app['db']->shouldReceive('select->from->where->one')->andReturn(['' => 'blah']);

$model = new TestModel(12);
$this->assertEquals('blah', $model->get('whatever'));
}

public function testRelation()
{
self::$app['db'] = Mockery::mock();
self::$app['db']->shouldReceive('select->from->where->one')->andReturn([]);

$model = new TestModel();
$model->relation = 2;

Expand Down

0 comments on commit 872b3a9

Please sign in to comment.