Add meta relation to all models

This commit is contained in:
James Brooks 2017-06-13 19:25:43 +01:00
parent 1faee910f3
commit 507ae3e4ed
5 changed files with 64 additions and 11 deletions

View File

@ -134,6 +134,16 @@ class Component extends Model implements HasPresenter
return $this->hasMany(Incident::class, 'component_id', 'id');
}
/**
* Get all of the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}
/**
* Get the tags relation.
*

View File

@ -145,7 +145,10 @@ class Incident extends Model implements HasPresenter
*
* @var string[]
*/
protected $with = ['updates'];
protected $with = [
'meta',
'updates',
];
/**
* Get the component relation.
@ -157,6 +160,16 @@ class Incident extends Model implements HasPresenter
return $this->belongsTo(Component::class, 'component_id', 'id');
}
/**
* Get all of the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}
/**
* Get the updates relation.
*

View File

@ -165,6 +165,16 @@ class Metric extends Model implements HasPresenter
});
}
/**
* Get all of the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}
/**
* Get the points relation.
*

View File

@ -131,6 +131,26 @@ class Schedule extends Model implements HasPresenter
*/
protected $with = ['components'];
/**
* Get the components relation.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function components()
{
return $this->hasMany(ScheduleComponent::class);
}
/**
* Get all of the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}
/**
* Scopes schedules to those in the future.
*
@ -155,16 +175,6 @@ class Schedule extends Model implements HasPresenter
return $query->where('status', '<', self::COMPLETE)->where('scheduled_at', '<=', Carbon::now());
}
/**
* Get the components relation.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function components()
{
return $this->hasMany(ScheduleComponent::class);
}
/**
* Get the presenter class.
*

View File

@ -90,6 +90,16 @@ class Subscriber extends Model implements HasPresenter
});
}
/**
* Get all of the meta relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function meta()
{
return $this->morphMany(Meta::class, 'meta');
}
/**
* Get the subscriptions relation.
*