diff --git a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php index 130c6c5860286a50025c5a7b0cb10717fbb18afc..a4e2e73f90eb71d0dbc94ea50c04957acbf7beaa 100644 --- a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php +++ b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php @@ -186,6 +186,16 @@ class EmbedsMany extends Relation { 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. * diff --git a/tests/RelationsTest.php b/tests/RelationsTest.php index d99be1814765e3ce71531d7d739b6a55a89cca78..c6ce2c77c46a86e07160a8d55b907dde5ebeccf4 100644 --- a/tests/RelationsTest.php +++ b/tests/RelationsTest.php @@ -327,6 +327,7 @@ class RelationsTest extends TestCase { $this->assertEquals(2, count($user->addresses)); $this->assertEquals(2, count($user->addresses()->get())); $this->assertEquals(2, $user->addresses->count()); + $this->assertEquals(2, $user->addresses()->count()); $this->assertEquals(array('London', 'New York'), $user->addresses->lists('city')); $freshUser = User::find($user->_id);