Skip to content

Commit

Permalink
Return empty collection from ::find() if not relations.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemorton committed Jul 13, 2012
1 parent 66f006b commit b77195b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions classes/TheCure/Relationships/HasManyRelationship.php
Expand Up @@ -22,14 +22,19 @@

use TheCure\Models\Model;

use TheCure\Collections\Collection;

class HasManyRelationship extends HasRelationship
implements AddRelation, RemoveRelation, ContainsRelation {

protected function where($object)
{
return array(
'_id' => array('$in' => $object->{$this->name()}),
);
if ($relation_ids = $object->{$this->name()})
{
return array(
'_id' => array('$in' => $relation_ids),
);
}
}

/**
Expand All @@ -43,7 +48,12 @@ public function find(Container $container, Model $model)
{
$accessor = new TransferObjectAccessor;
$object = $accessor->get($model);
$where = $this->where($object);

if ( ! $where = $this->where($object))
{
return new Collection(array());
}

return $this->mapper($container)->find(
$where,
$this->modelSuffix());
Expand Down

0 comments on commit b77195b

Please sign in to comment.