Skip to content

Commit

Permalink
Merge d05404b into ec89233
Browse files Browse the repository at this point in the history
  • Loading branch information
divine committed Mar 10, 2020
2 parents ec89233 + d05404b commit c5ba241
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 106 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ All notable changes to this project will be documented in this file.
### Removed
- EmbedsOne and EmbedsMany relations by [@divine](https://github.com/divine).
- shouldUseCollections function by [@divine](https://github.com/divine).
- Dot notation support in keys by [@divine](https://github.com/divine).
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -952,5 +952,6 @@ Upgrading
This new major release contains breaking changes which is listed below:

- EmbedsOne and EmbedsMany relations has been removed completely. See explanation [here](https://github.com/jenssegers/laravel-mongodb/issues/1974#issuecomment-592859508)
- Dot notation support for keys has been removed completely. See explanation [here](https://github.com/jenssegers/laravel-mongodb/issues/1974#issuecomment-593113728)

For any other minor changes, please take a look at our [changelog](CHANGELOG.md)
26 changes: 0 additions & 26 deletions src/Jenssegers/Mongodb/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ public function getAttribute($key)
return;
}

// Dot notation support.
if (Str::contains($key, '.') && Arr::has($this->attributes, $key)) {
return $this->getAttributeValue($key);
}

return parent::getAttribute($key);
}

Expand All @@ -151,11 +146,6 @@ public function getAttribute($key)
*/
protected function getAttributeFromArray($key)
{
// Support keys in dot notation.
if (Str::contains($key, '.')) {
return Arr::get($this->attributes, $key);
}

return parent::getAttributeFromArray($key);
}

Expand All @@ -169,15 +159,6 @@ public function setAttribute($key, $value)
$builder = $this->newBaseQueryBuilder();

$value = $builder->convertKey($value);
} // Support keys in dot notation.
elseif (Str::contains($key, '.')) {
if (in_array($key, $this->getDates()) && $value) {
$value = $this->fromDateTime($value);
}

Arr::set($this->attributes, $key, $value);

return;
}

return parent::setAttribute($key, $value);
Expand All @@ -202,13 +183,6 @@ public function attributesToArray()
}
}

// Convert dot-notation dates.
foreach ($this->getDates() as $key) {
if (Str::contains($key, '.') && Arr::has($attributes, $key)) {
Arr::set($attributes, $key, (string) $this->asDateTime(Arr::get($attributes, $key)));
}
}

return $attributes;
}

Expand Down
49 changes: 0 additions & 49 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,6 @@ public function testDates(): void

$user = User::create(['name' => 'Jane Doe', 'birthday' => '2005-08-08']);
$this->assertInstanceOf(Carbon::class, $user->birthday);

$user = User::create(['name' => 'Jane Doe', 'entry' => ['date' => '2005-08-08']]);
$this->assertInstanceOf(Carbon::class, $user->getAttribute('entry.date'));

$user->setAttribute('entry.date', new DateTime);
$this->assertInstanceOf(Carbon::class, $user->getAttribute('entry.date'));

$data = $user->toArray();
$this->assertNotInstanceOf(UTCDateTime::class, $data['entry']['date']);
$this->assertEquals((string) $user->getAttribute('entry.date')->format('Y-m-d H:i:s'), $data['entry']['date']);
}

public function testCarbonDateMockingWorks()
Expand Down Expand Up @@ -508,45 +498,6 @@ public function testRaw(): void
$this->assertNotNull($result);
}

public function testDotNotation(): void
{
$user = User::create([
'name' => 'John Doe',
'address' => [
'city' => 'Paris',
'country' => 'France',
],
]);

$this->assertEquals('Paris', $user->getAttribute('address.city'));
$this->assertEquals('Paris', $user['address.city']);
$this->assertEquals('Paris', $user->{'address.city'});

// Fill
$user->fill([
'address.city' => 'Strasbourg',
]);

$this->assertEquals('Strasbourg', $user['address.city']);
}

public function testMultipleLevelDotNotation(): void
{
/** @var Book $book */
$book = Book::create([
'title' => 'A Game of Thrones',
'chapters' => [
'one' => [
'title' => 'The first chapter',
],
],
]);

$this->assertEquals(['one' => ['title' => 'The first chapter']], $book->chapters);
$this->assertEquals(['title' => 'The first chapter'], $book['chapters.one']);
$this->assertEquals('The first chapter', $book['chapters.one.title']);
}

public function testGetDirtyDates(): void
{
$user = new User();
Expand Down
26 changes: 0 additions & 26 deletions tests/RelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,32 +457,6 @@ public function testHasOneHas(): void
$this->assertCount(2, $users);
}

public function testNestedKeys(): void
{
$client = Client::create([
'data' => [
'client_id' => 35298,
'name' => 'John Doe',
],
]);

$client->addresses()->create([
'data' => [
'address_id' => 1432,
'city' => 'Paris',
],
]);

$client = Client::where('data.client_id', 35298)->first();
$this->assertEquals(1, $client->addresses->count());

$address = $client->addresses->first();
$this->assertEquals('Paris', $address->data['city']);

$client = Client::with('addresses')->first();
$this->assertEquals('Paris', $client->addresses->first()->data['city']);
}

public function testDoubleSaveOneToMany(): void
{
$author = User::create(['name' => 'George R. R. Martin']);
Expand Down
5 changes: 0 additions & 5 deletions tests/models/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,4 @@ public function photo(): MorphOne
{
return $this->morphOne('Photo', 'imageable');
}

public function addresses(): HasMany
{
return $this->hasMany('Address', 'data.client_id', 'data.client_id');
}
}

0 comments on commit c5ba241

Please sign in to comment.