diff --git a/src/Commands/Store.php b/src/Commands/Store.php index ca097e0..07fbc85 100755 --- a/src/Commands/Store.php +++ b/src/Commands/Store.php @@ -186,6 +186,10 @@ protected function insert() unset($attributes[$keyName]); } + if (isset($attributes['attributes'])) { + unset($attributes['attributes']); + } + $id = $this->query->insertGetId($attributes, $keyName); $aggregate->setEntityAttribute($keyName, $id); diff --git a/src/EntityMap.php b/src/EntityMap.php index 2f6cc6b..d134da4 100755 --- a/src/EntityMap.php +++ b/src/EntityMap.php @@ -1572,10 +1572,7 @@ public function getMorphClass(): string */ public function newCollection(array $entities = []): EntityCollection { - $collection = new EntityCollection($entities); - $keyName = $this->getAttributeNameForColumn($this->getKeyName()); - - return $collection->keyBy($keyName); + return new EntityCollection($entities); } /** @@ -1745,6 +1742,7 @@ public function getAttributeNamesFromColumns($array) return $newArray; } if ($this->camelCaseHydratation) { + $newArray = []; foreach ($array as $key => $value) { $attributeName = camel_case($key); $newArray[$attributeName] = $value; @@ -1796,6 +1794,7 @@ public function getColumnNamesFromAttributes($array) return $newArray; } if ($this->camelCaseHydratation) { + $newArray = []; foreach ($array as $key => $value) { $attributeName = snake_case($key); $newArray[$attributeName] = $value; diff --git a/src/System/Wrappers/ObjectWrapper.php b/src/System/Wrappers/ObjectWrapper.php index 7d40570..5a78ac0 100644 --- a/src/System/Wrappers/ObjectWrapper.php +++ b/src/System/Wrappers/ObjectWrapper.php @@ -167,7 +167,7 @@ protected function dehydrate($entity): array if (isset($properties[$attributesName])) { $properties[$attributesName] = $this->entityMap->getColumnNamesFromAttributes($properties[$attributesName]); } else { - $properties = $this->entityMap->getColumnNamesFromAttributes($properties); + $properties[$attributesName] = $this->entityMap->getColumnNamesFromAttributes($properties); } $this->properties = $properties; @@ -191,7 +191,7 @@ protected function hydrate() if (isset($properties[$attributesName])) { $properties[$attributesName] = $this->entityMap->getAttributeNamesFromColumns($properties[$attributesName]); } else { - $properties = $this->entityMap->getAttributeNamesFromColumns($properties); + $properties[$attributesName] = $this->entityMap->getAttributeNamesFromColumns($properties); } // In some case, attributes will miss some properties, so we'll just complete the hydration diff --git a/tests/cases/EntityTest.php b/tests/cases/EntityTest.php index e9a7012..8dab821 100755 --- a/tests/cases/EntityTest.php +++ b/tests/cases/EntityTest.php @@ -100,6 +100,11 @@ public function we_can_access_mapped_columns() $user = $mapper->find($id); $this->assertEquals('123456', $user->rememberToken); $this->assertEquals('adro', $user->identity->fname); + $user->rememberToken = '1234567'; + $mapper->store($user); + $user = null; + $user = $mapper->find($id); + $this->assertEquals('1234567', $user->rememberToken); } /** @test */ @@ -113,6 +118,15 @@ public function we_can_access_camel_case_properities() $movie = null; $movie = $mapper->find($id); $this->assertEquals('analogue is awesome', $movie->getSomeText()); + $movie->setSomeText('analogue is awesome!!'); + $mapper->store($movie); + $movie = null; + $movie2 = $mapper->find($id); + $this->assertEquals('analogue is awesome!!', $movie2->getSomeText()); + $this->seeInDatabase('movies', [ + 'title' => 'Analogue Tutorial', + 'some_text' => 'analogue is awesome!!', + ]); } /** @test */ diff --git a/tests/src/Maps/MovieMap.php b/tests/src/Maps/MovieMap.php index 8157f9b..fce3db4 100755 --- a/tests/src/Maps/MovieMap.php +++ b/tests/src/Maps/MovieMap.php @@ -12,12 +12,11 @@ class MovieMap extends EntityMap 'id', 'title', 'realisator', + 'some_text', ]; protected $camelCaseHydratation = true; - protected $arrayName = null; - public function realisator(Movie $movie) { return $this->belongsTo($movie, Realisator::class);