mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-08 22:03:16 +01:00
Models that belong to an organization via a parent model (for example project members via their project) implement AuditableThroughParent and return the parent relation. The owner organization of their audits is taken from the loaded parent if it matches the foreign key, otherwise it is queried. The declaration is also used to backfill the owner of existing audits.
23 lines
718 B
PHP
23 lines
718 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models\Concerns;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* Marks an auditable model whose audits are owned by the owner of its parent model,
|
|
* because the model itself has no organization_id (for example a project member belongs to an organization via its project).
|
|
* The parent model has to have an organization_id column.
|
|
* This is used to set the owner of new audits (CustomAuditable) and to backfill the owner of existing audits.
|
|
*/
|
|
interface AuditableThroughParent
|
|
{
|
|
/**
|
|
* @return BelongsTo<covariant Model, covariant Model>
|
|
*/
|
|
public function getAuditParentRelation(): BelongsTo;
|
|
}
|