Commit f3f1f8ef authored by Jens Segers's avatar Jens Segers

Adding count to embedsMany, fixes #177

parent a1451be3
...@@ -186,6 +186,16 @@ class EmbedsMany extends Relation { ...@@ -186,6 +186,16 @@ class EmbedsMany extends Relation {
return false; return false;
} }
/**
* Get the number of embedded documents.
*
* @return int
*/
public function count()
{
return count($this->getEmbeddedRecords());
}
/** /**
* Attach a model instance to the parent model without persistence. * Attach a model instance to the parent model without persistence.
* *
......
...@@ -327,6 +327,7 @@ class RelationsTest extends TestCase { ...@@ -327,6 +327,7 @@ class RelationsTest extends TestCase {
$this->assertEquals(2, count($user->addresses)); $this->assertEquals(2, count($user->addresses));
$this->assertEquals(2, count($user->addresses()->get())); $this->assertEquals(2, count($user->addresses()->get()));
$this->assertEquals(2, $user->addresses->count()); $this->assertEquals(2, $user->addresses->count());
$this->assertEquals(2, $user->addresses()->count());
$this->assertEquals(array('London', 'New York'), $user->addresses->lists('city')); $this->assertEquals(array('London', 'New York'), $user->addresses->lists('city'));
$freshUser = User::find($user->_id); $freshUser = User::find($user->_id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment