Commit b23b59ee authored by Jens Segers's avatar Jens Segers

Using underscore attribute for embedsMany, check #138

parent 128eb7b5
......@@ -57,16 +57,6 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*/
protected function embedsMany($related, $localKey = null, $foreignKey = null, $relation = null)
{
if (is_null($localKey))
{
$localKey = snake_case(str_plural($related)) . '_ids';
}
if (is_null($foreignKey))
{
$foreignKey = snake_case(class_basename($this));
}
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relatinoships.
......@@ -77,6 +67,16 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
$relation = $caller['function'];
}
if (is_null($localKey))
{
$localKey = '_' . $relation;
}
if (is_null($foreignKey))
{
$foreignKey = snake_case(class_basename($this));
}
$query = $this->newQuery();
$instance = new $related;
......
......@@ -289,6 +289,7 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
$address = new Address(array('city' => 'London'));
$address = $user->addresses()->save($address);
$this->assertNotNull($user->_addresses);
$this->assertEquals(array('London'), $user->addresses->lists('city'));
$this->assertInstanceOf('DateTime', $address->created_at);
$this->assertInstanceOf('DateTime', $address->updated_at);
......
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