From 6de86f7ffb96b9d22c56708781fb5bbd09d20398 Mon Sep 17 00:00:00 2001 From: Sang Lu Date: Tue, 26 Mar 2019 09:34:52 +0700 Subject: [PATCH] Fix bug lack a reference method when two FKs in a table references to a same table --- src/Coders/Model/Factory.php | 4 ++-- src/Coders/Model/Model.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Coders/Model/Factory.php b/src/Coders/Model/Factory.php index d3ffdece..10792f0f 100644 --- a/src/Coders/Model/Factory.php +++ b/src/Coders/Model/Factory.php @@ -458,8 +458,8 @@ protected function body(Model $model) $body .= $this->class->method($mutation->name(), $mutation->body(), ['before' => "\n"]); } - foreach ($model->getRelations() as $constraint) { - $body .= $this->class->method($constraint->name(), $constraint->body(), ['before' => "\n"]); + foreach ($model->getRelations() as $k => $constraint) { + $body .= $this->class->method(Str::camel($k), $constraint->body(), ['before' => "\n"]); } // Make sure there not undesired line breaks diff --git a/src/Coders/Model/Model.php b/src/Coders/Model/Model.php index 25c03849..a1af9a49 100644 --- a/src/Coders/Model/Model.php +++ b/src/Coders/Model/Model.php @@ -232,7 +232,7 @@ protected function fill() foreach ($this->blueprint->relations() as $relation) { $model = $this->makeRelationModel($relation); $belongsTo = new BelongsTo($relation, $this, $model); - $this->relations[$belongsTo->name()] = $belongsTo; + $this->relations[implode('_', $relation->get('columns'))] = $belongsTo; } foreach ($this->factory->referencing($this) as $related) {