Fixing bugs and improving.
Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
parent
b5e75f6fcf
commit
762f2402c3
|
@ -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.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?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 @@ public function add($id, $attributes = array())
|
|||
*/
|
||||
public function insert($attributes, $joining = array())
|
||||
{
|
||||
$id = $this->table->insert_get_id($attributes, $this->model->sequence());
|
||||
$model = $this->model->create($attributes);
|
||||
|
||||
$result = $this->insert_joining(array_merge($this->join_record($id), $joining));
|
||||
// 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 @@ public function insert($attributes)
|
|||
{
|
||||
$attributes[$this->foreign_key()] = $this->base->get_key();
|
||||
|
||||
return parent::insert($attributes);
|
||||
return $this->model->create($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,6 +68,19 @@ public static function foreign($model, $foreign = null)
|
|||
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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue