From e96f75e8cc889b09528a18612b0373bbc931b527 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 22 Mar 2012 13:12:27 -0500 Subject: [PATCH] Fixing bugs in database layer. --- .../eloquent/relationships/relationship.php | 24 +++++++++++++------ laravel/database/schema/table.php | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/laravel/database/eloquent/relationships/relationship.php b/laravel/database/eloquent/relationships/relationship.php index 1ce9f31b..f6ccc484 100644 --- a/laravel/database/eloquent/relationships/relationship.php +++ b/laravel/database/eloquent/relationships/relationship.php @@ -24,11 +24,21 @@ public function __construct($model, $associated, $foreign) { $this->foreign = $foreign; - // We will go ahead and set the model and associated instances on the relationship - // to match the relationship targets passed in from the model. These will allow - // us to gather more inforamtion on the relationship. - $this->model = ($associated instanceof Model) ? $associated : new $associated; + // We will go ahead and set the model and associated instances on the + // relationship to match the relationship targets passed in from the + // model. These will allow us to gather the relationship info. + 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) { $this->base = $model; @@ -38,9 +48,9 @@ public function __construct($model, $associated, $foreign) $this->base = new $model; } - // Next we'll set the fluent query builder for the relationship and constrain - // the query such that it only returns the models that are appropriate for - // the relationship, typically by setting the foreign key. + // Next we'll set the fluent query builder for the relationship and + // constrain the query such that it only returns the models that + // are appropriate for the relationship. $this->table = $this->query(); $this->constrain(); diff --git a/laravel/database/schema/table.php b/laravel/database/schema/table.php index add48770..9518d6e7 100644 --- a/laravel/database/schema/table.php +++ b/laravel/database/schema/table.php @@ -136,7 +136,7 @@ public function key($type, $columns, $name) // the index that can be used when dropping indexes. if (is_null($name)) { - $name = $this->name.implode('_', $columns).'_'.$type; + $name = $this->name.'_'.implode('_', $columns).'_'.$type; } return $this->command($type, compact('name', 'columns'));