Optimised Organisation model to prevent it running 4 extra queries per instance
This commit is contained in:
@@ -65,8 +65,7 @@ class Organisation extends Model implements OrganisationInterface
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = [
|
||||
'member_count',
|
||||
'admin_count'
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -84,30 +83,6 @@ class Organisation extends Model implements OrganisationInterface
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
/**
|
||||
* Get a count of members within this organisation (includes admins).
|
||||
*/
|
||||
public function getMemberCountAttribute()
|
||||
{
|
||||
return $this->members()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a count of administrators within this organisation.
|
||||
*/
|
||||
public function getAdminCountAttribute()
|
||||
{
|
||||
return $this->administrators()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a count of members within this organisation (excludes admins).
|
||||
*/
|
||||
public function getTotalMemberCountAttribute()
|
||||
{
|
||||
return $this->members()->count() + $this->administrators()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of members within this organisation.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user