Commit 762f2402 authored by Taylor Otwell's avatar Taylor Otwell

Fixing bugs and improving.

Signed-off-by: 's avatarTaylor Otwell <taylorotwell@gmail.com>
parent b5e75f6f
......@@ -59,7 +59,7 @@ abstract class Model {
*
* @var bool
*/
public static $timestamps = false;
public static $timestamps = true;
/**
* The name of the table associated with the model.
......
<?php namespace Laravel\Database\Eloquent\Relationships;
use Laravel\Database\Eloquent\Model;
use Laravel\Database\Eloquent\Pivot;
class Has_Many_And_Belongs_To extends Relationship {
......@@ -23,7 +24,7 @@ class Has_Many_And_Belongs_To extends Relationship {
*
* @var array
*/
protected $with = array('created_at', 'updated_at');
protected $with = array('id', 'created_at', 'updated_at');
/**
* Create a new many to many relationship instance.
......@@ -93,11 +94,17 @@ class Has_Many_And_Belongs_To extends Relationship {
*/
public function insert($attributes, $joining = array())
{
$id = $this->table->insert_get_id($attributes, $this->model->sequence());
$model = $this->model->create($attributes);
// If the insert was successful, we'll insert a record into the joining table
// using the new ID that was just inserted into the related table, allowing
// the developer to not worry about maintaining the join table.
if ($model instanceof Model and is_numeric($id = $model->get_key()))
{
$result = $this->insert_joining(array_merge($this->join_record($id), $joining));
}
return is_numeric($id) and $result;
return $model instanceof Model and $result;
}
/**
......
......@@ -14,7 +14,7 @@ class Has_One_Or_Many extends Relationship {
{
$attributes[$this->foreign_key()] = $this->base->get_key();
return parent::insert($attributes);
return $this->model->create($attributes);
}
/**
......
......@@ -68,6 +68,19 @@ abstract class Relationship extends Query {
return strtolower(basename($model).'_id');
}
/**
* Get a freshly instantiated instance of the related model class.
*
* @param array $attributes
* @return Model
*/
protected function fresh_model($attributes = array())
{
$class = get_class($this->model);
return new $class($attributes);
}
/**
* Get the foreign key for the relationship.
*
......
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