Fixing bugs in database layer.
This commit is contained in:
parent
35e53b8cef
commit
e96f75e8cc
|
@ -24,11 +24,21 @@ public function __construct($model, $associated, $foreign)
|
||||||
{
|
{
|
||||||
$this->foreign = $foreign;
|
$this->foreign = $foreign;
|
||||||
|
|
||||||
// We will go ahead and set the model and associated instances on the relationship
|
// We will go ahead and set the model and associated instances on the
|
||||||
// to match the relationship targets passed in from the model. These will allow
|
// relationship to match the relationship targets passed in from the
|
||||||
// us to gather more inforamtion on the relationship.
|
// model. These will allow us to gather the relationship info.
|
||||||
$this->model = ($associated instanceof Model) ? $associated : new $associated;
|
if ($associated instanceof Model)
|
||||||
|
{
|
||||||
|
$this->model = $associated;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->model = new $associated;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For relationships, we'll set the base model to be the model being
|
||||||
|
// associated from. This model contains the value of the foreign
|
||||||
|
// key needed to connect to the associated model.
|
||||||
if ($model instanceof Model)
|
if ($model instanceof Model)
|
||||||
{
|
{
|
||||||
$this->base = $model;
|
$this->base = $model;
|
||||||
|
@ -38,9 +48,9 @@ public function __construct($model, $associated, $foreign)
|
||||||
$this->base = new $model;
|
$this->base = new $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next we'll set the fluent query builder for the relationship and constrain
|
// Next we'll set the fluent query builder for the relationship and
|
||||||
// the query such that it only returns the models that are appropriate for
|
// constrain the query such that it only returns the models that
|
||||||
// the relationship, typically by setting the foreign key.
|
// are appropriate for the relationship.
|
||||||
$this->table = $this->query();
|
$this->table = $this->query();
|
||||||
|
|
||||||
$this->constrain();
|
$this->constrain();
|
||||||
|
|
|
@ -136,7 +136,7 @@ public function key($type, $columns, $name)
|
||||||
// the index that can be used when dropping indexes.
|
// the index that can be used when dropping indexes.
|
||||||
if (is_null($name))
|
if (is_null($name))
|
||||||
{
|
{
|
||||||
$name = $this->name.implode('_', $columns).'_'.$type;
|
$name = $this->name.'_'.implode('_', $columns).'_'.$type;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->command($type, compact('name', 'columns'));
|
return $this->command($type, compact('name', 'columns'));
|
||||||
|
|
Loading…
Reference in New Issue