Prevent undefined property errors (#877)

If the property name matches the foreign key name
creating a BelongsTo relation triggers an undefined
property error. Disabling constraints prevents
accessing the property and thus prevents the error.
This commit is contained in:
Matt A
2020-01-12 17:51:04 +01:00
committed by Barry vd. Heuvel
parent 805c4e9a2a
commit 972befd7aa
3 changed files with 21 additions and 3 deletions
@@ -62,4 +62,9 @@ class Simple extends Model
{
return $this->belongsTo(AnotherModel::class);
}
public function relationBelongsToSameNameAsColumn(): BelongsTo
{
return $this->belongsTo(AnotherModel::class, __FUNCTION__);
}
}
@@ -73,6 +73,7 @@ use Illuminate\Database\Eloquent\Relations\MorphToMany;
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\ModelsOtherNamespace\AnotherModel $relationBelongsToInAnotherNamespace
* @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationBelongsToMany
* @property-read int|null $relation_belongs_to_many_count
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\ModelsOtherNamespace\AnotherModel $relationBelongsToSameNameAsColumn
* @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationHasMany
* @property-read int|null $relation_has_many_count
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple $relationHasOne
@@ -136,6 +137,11 @@ class Simple extends Model
{
return $this->belongsTo(AnotherModel::class);
}
public function relationBelongsToSameNameAsColumn(): BelongsTo
{
return $this->belongsTo(AnotherModel::class, __FUNCTION__);
}
}
PHP;