added support for overriding many-to-many table names.
This commit is contained in:
parent
ae7114163a
commit
9cee469371
|
@ -164,11 +164,12 @@ public function belongs_to($model)
|
|||
* Retrieve the query for a *:* relationship.
|
||||
*
|
||||
* @param string $model
|
||||
* @param string $table
|
||||
* @return mixed
|
||||
*/
|
||||
public function has_many_and_belongs_to($model)
|
||||
public function has_many_and_belongs_to($model, $table = null)
|
||||
{
|
||||
return Eloquent\Relate::has_many_and_belongs_to($model, $this);
|
||||
return Eloquent\Relate::has_many_and_belongs_to($model, $table, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -64,18 +64,27 @@ public static function belongs_to($caller, $model, $eloquent)
|
|||
* Retrieve the query for a *:* relationship.
|
||||
*
|
||||
* @param string $model
|
||||
* @param string $table
|
||||
* @param object $eloquent
|
||||
* @return mixed
|
||||
*/
|
||||
public static function has_many_and_belongs_to($model, $eloquent)
|
||||
public static function has_many_and_belongs_to($model, $table, $eloquent)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Get the models involved in the relationship.
|
||||
// Figure out the intermediate table name.
|
||||
// -----------------------------------------------------
|
||||
if (is_null($table))
|
||||
{
|
||||
$models = array(\System\Str::lower($model), \System\Str::lower(get_class($eloquent)));
|
||||
sort($models);
|
||||
|
||||
$eloquent->relating_table = implode('_', $models);
|
||||
}
|
||||
else
|
||||
{
|
||||
$eloquent->relating_table = $table;
|
||||
}
|
||||
|
||||
$eloquent->relating = __FUNCTION__;
|
||||
$eloquent->relating_key = $eloquent->relating_table.'.'.\System\Str::lower(get_class($eloquent)).'_id';
|
||||
|
||||
|
|
Loading…
Reference in New Issue