Created
January 30, 2014 17:13
-
-
Save pmjones/8713662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/Aura/Marshal/Entity/GenericEntity.php b/src/Aura/Marshal/Entity/GenericEntity.php | |
| index 8e643eb..cc2d82d 100644 | |
| --- a/src/Aura/Marshal/Entity/GenericEntity.php | |
| +++ b/src/Aura/Marshal/Entity/GenericEntity.php | |
| @@ -22,4 +22,29 @@ use Aura\Marshal\Data; | |
| class GenericEntity extends Data | |
| { | |
| use MagicArrayAccessTrait; | |
| + | |
| + /** | |
| + * | |
| + * ArrayAccess: get a key value. | |
| + * | |
| + * @param string $field The requested field. | |
| + * | |
| + * @return mixed | |
| + * | |
| + */ | |
| + public function offsetGet($field) | |
| + { | |
| + // get the field value | |
| + $value = $this->data[$field]; | |
| + | |
| + // is it a Lazy placeholder? | |
| + if ($value instanceof LazyInterface) { | |
| + // replace the Lazy placeholder with the real object | |
| + $value = $value->get($this); | |
| + $this->offsetSet($field, $value); | |
| + } | |
| + | |
| + // done! | |
| + return $value; | |
| + } | |
| } | |
| diff --git a/tests/Aura/Marshal/RelationTest.php b/tests/Aura/Marshal/RelationTest.php | |
| index 8b1bca9..407ed4a 100644 | |
| --- a/tests/Aura/Marshal/RelationTest.php | |
| +++ b/tests/Aura/Marshal/RelationTest.php | |
| @@ -190,4 +190,14 @@ class RelationTest extends \PHPUnit_Framework_TestCase | |
| $this->assertSame($expect[$offset]['name'], $tag->name); | |
| } | |
| } | |
| + | |
| + public function testIteratorToArrayEntityHasRelationships() | |
| + { | |
| + $posts = $this->manager->posts->getCollection($this->manager->posts->getIdentityValues()); | |
| + $postsArray = iterator_to_array($posts); | |
| + | |
| + $this->assertCount(3, $postsArray[0]['comments']); | |
| + $this->assertCount(2, $postsArray[0]['tags']); | |
| + $this->assertEquals('Anna', $postsArray[0]['author']['name']); | |
| + } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment