-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix relation name infering when MorphOne/MorphMany (#473)
- Loading branch information
Showing
4 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
tests/fixtures/drafts/model-relationships-morphone-morphmany-with-fqn.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
models: | ||
Flag: | ||
user_id: id | ||
relationships: | ||
morphOne: \Other\Package\Order:stars | ||
morphMany: \Other\Package\Duration, \App\MyCustom\Folder\Transaction:line |
51 changes: 51 additions & 0 deletions
51
tests/fixtures/models/model-relationships-morphone-morphmany-with-fqn-laravel8.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Flag extends Model | ||
{ | ||
use HasFactory; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'user_id', | ||
]; | ||
|
||
/** | ||
* The attributes that should be cast to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'id' => 'integer', | ||
'user_id' => 'integer', | ||
]; | ||
|
||
|
||
public function stars() | ||
{ | ||
return $this->morphOne(\Other\Package\Order::class, 'starable'); | ||
} | ||
|
||
public function durations() | ||
{ | ||
return $this->morphMany(\Other\Package\Duration::class, 'durationable'); | ||
} | ||
|
||
public function lines() | ||
{ | ||
return $this->morphMany(\App\MyCustom\Folder\Transaction::class, 'lineable'); | ||
} | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo(\App\User::class); | ||
} | ||
} |