Commit 00249c1f authored by Jens Segers's avatar Jens Segers

Fixes #236

parent c29d5301
......@@ -222,7 +222,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
public function getAttribute($key)
{
// Check if the key is an array dot notation.
if (strpos($key, '.') !== false)
if (str_contains($key, '.'))
{
$attributes = array_dot($this->attributes);
......@@ -274,7 +274,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
return $this->attributes[$key];
}
else if (strpos($key, '.') !== false)
elseif (str_contains($key, '.'))
{
$attributes = array_dot($this->attributes);
......@@ -302,6 +302,17 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
$value = $builder->convertKey($value);
}
// Support keys in dot notation.
elseif (str_contains($key, '.'))
{
if (in_array($key, $this->getDates()) && $value)
{
$value = $this->fromDateTime($value);
}
array_set($this->attributes, $key, $value); return;
}
parent::setAttribute($key, $value);
}
......
......@@ -20,4 +20,14 @@ class HasMany extends EloquentHasMany {
return $query->select($this->getHasCompareKey())->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Get the plain foreign key.
*
* @return string
*/
public function getPlainForeignKey()
{
return $this->getForeignKey();
}
}
......@@ -20,4 +20,14 @@ class HasOne extends EloquentHasOne {
return $query->select($this->getHasCompareKey())->where($this->getHasCompareKey(), 'exists', true);
}
/**
* Get the plain foreign key.
*
* @return string
*/
public function getPlainForeignKey()
{
return $this->getForeignKey();
}
}
......@@ -131,6 +131,7 @@ class RelationsTest extends TestCase {
$items = $user->items;
$this->assertEquals(1, count($items));
$this->assertInstanceOf('Item', $items[0]);
$this->assertEquals($user->_id, $items[0]->user_id);
// Has one
$user = User::create(array('name' => 'John Doe'));
......@@ -141,6 +142,7 @@ class RelationsTest extends TestCase {
$role = $user->role;
$this->assertInstanceOf('Role', $role);
$this->assertEquals('admin', $role->type);
$this->assertEquals($user->_id, $role->user_id);
}
public function testBelongsToMany()
......@@ -415,6 +417,9 @@ class RelationsTest extends TestCase {
$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()
......
......@@ -19,6 +19,6 @@ class Client extends Eloquent {
public function addresses()
{
return $this->hasMany('Address', 'data.client_id', 'data.address_id');
return $this->hasMany('Address', 'data.address_id', 'data.client_id');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment