mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-10-25 06:37:36 +03:00
Updated uses of user ID to nullify on delete. Added testing to cover deletion of user relations. Added model factories to support changes and potential other tests. Cleans existing ID references in the DB via migration.
31 lines
777 B
PHP
31 lines
777 B
PHP
<?php
|
|
|
|
namespace BookStack\Activity\Models;
|
|
|
|
use BookStack\App\Model;
|
|
use BookStack\Permissions\Models\JointPermission;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
class Favourite extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = ['user_id'];
|
|
|
|
/**
|
|
* Get the related model that can be favourited.
|
|
*/
|
|
public function favouritable(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
public function jointPermissions(): HasMany
|
|
{
|
|
return $this->hasMany(JointPermission::class, 'entity_id', 'favouritable_id')
|
|
->whereColumn('favourites.favouritable_type', '=', 'joint_permissions.entity_type');
|
|
}
|
|
}
|