Skip to content

Commit 66de10e

Browse files
committed
Adding tests for #236
1 parent bc842c0 commit 66de10e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/RelationsTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public function tearDown()
77
Mockery::close();
88

99
User::truncate();
10+
Client::truncate();
11+
Address::truncate();
1012
Book::truncate();
1113
Item::truncate();
1214
Role::truncate();
@@ -392,4 +394,27 @@ public function testHasOneHas()
392394
$this->assertCount(2, $users);
393395
}
394396

397+
public function testNestedKeys()
398+
{
399+
$client = Client::create(array(
400+
'data' => array(
401+
'client_id' => 35298,
402+
'name' => 'John Doe'
403+
)
404+
));
405+
406+
$address = $client->addresses()->create(array(
407+
'data' => array(
408+
'address_id' => 1432,
409+
'city' => 'Paris'
410+
)
411+
));
412+
413+
$client = Client::where('data.client_id', 35298)->first();
414+
$this->assertEquals(1, $client->addresses->count());
415+
416+
$address = $client->addresses->first();
417+
$this->assertEquals('Paris', $address->data['city']);
418+
}
419+
395420
}

tests/models/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ public function photo()
1616
{
1717
return $this->morphOne('Photo', 'imageable');
1818
}
19+
20+
public function addresses()
21+
{
22+
return $this->hasMany('Address', 'data.client_id', 'data.address_id');
23+
}
1924
}

0 commit comments

Comments
 (0)