mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
An attempt to make checkout accessories a multimorph relationship
This commit is contained in:
parent
b917489f00
commit
d6eb04a815
|
@ -255,8 +255,21 @@ class Accessory extends SnipeModel
|
|||
*/
|
||||
public function checkouts()
|
||||
{
|
||||
return $this->hasMany(\App\Models\AccessoryCheckout::class, 'accessory_id')
|
||||
->with('assignedTo');
|
||||
return $this->morphToMany(Accessory::class, 'assignedAccessories', 'accessories_checkout', 'assigned_to', null,);
|
||||
}
|
||||
|
||||
public function locationAssignments()
|
||||
{
|
||||
//I don't nkow that we'll want this, but this is a thing we can do - find the locations that have been assigned this accessory
|
||||
return $this->morphedByMany(Location::class, 'accessory_assignment');
|
||||
|
||||
}
|
||||
|
||||
public function userAssignments()
|
||||
{
|
||||
//I don't nkow that we'll want this, but this is a thing we can do - find the locations that have been assigned this accessory
|
||||
return $this->morphedByMany(User::class, 'accessory_assignment');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -253,6 +253,21 @@ class Location extends SnipeModel
|
|||
return $this->morphMany(\App\Models\Asset::class, 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
|
||||
}
|
||||
|
||||
public function assignedAccessories()
|
||||
{
|
||||
return $this->morphToMany(
|
||||
Accessory::class,
|
||||
'accessory_assignment',
|
||||
'accessories_checkout',
|
||||
'assigned_to',
|
||||
'assigned_type',
|
||||
null,
|
||||
null,
|
||||
'accessory_assignment',
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function setLdapOuAttribute($ldap_ou)
|
||||
{
|
||||
return $this->attributes['ldap_ou'] = empty($ldap_ou) ? null : $ldap_ou;
|
||||
|
|
Loading…
Reference in a new issue