mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
At least in Tinker this seems to basically have all of the right relationships
This commit is contained in:
parent
b917489f00
commit
6f6a5f5412
|
@ -255,8 +255,7 @@ class Accessory extends SnipeModel
|
|||
*/
|
||||
public function checkouts()
|
||||
{
|
||||
return $this->hasMany(\App\Models\AccessoryCheckout::class, 'accessory_id')
|
||||
->with('assignedTo');
|
||||
return $this->hasMany(\App\Models\AccessoryCheckout::class, 'accessory_id'); // TODO - is that right, is that what I want?
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -45,7 +45,7 @@ class AccessoryCheckout extends Model
|
|||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
{ // This needs fixing
|
||||
return $this->hasOne(\App\Models\User::class, 'user_id');
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ class AccessoryCheckout extends Model
|
|||
*/
|
||||
public function assignedTo()
|
||||
{
|
||||
return $this->morphTo('assigned', 'assigned_type', 'assigned_to')->withTrashed();
|
||||
return $this->morphTo('assigned' /* this? */, 'assigned_type', 'assigned_to')->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -249,10 +249,15 @@ class Location extends SnipeModel
|
|||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assignedAssets()
|
||||
{
|
||||
{ //the morph relationship is weird here?
|
||||
return $this->morphMany(\App\Models\Asset::class, 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
|
||||
}
|
||||
|
||||
public function assignedAccessories()
|
||||
{
|
||||
return $this->morphMany(AccessoryCheckout::class, 'assigned', 'assigned_type', 'assigned_to');
|
||||
}
|
||||
|
||||
public function setLdapOuAttribute($ldap_ou)
|
||||
{
|
||||
return $this->attributes['ldap_ou'] = empty($ldap_ou) ? null : $ldap_ou;
|
||||
|
|
|
@ -331,6 +331,13 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
|||
*/
|
||||
public function accessories()
|
||||
{
|
||||
/*******************************
|
||||
*
|
||||
* so 'assignedTo' as the name returns 'unknown column accessories_checkout.assignedTo_type'
|
||||
* 'assigned' returns 'unknown column accessories_checkout.assigned_id'
|
||||
*/
|
||||
return $this->morphMany(AccessoryCheckout::class, 'assigned', 'assigned_type', 'assigned_to');
|
||||
//no, wrong. I mean, it's skipping the polymorphic-ness
|
||||
return $this->belongsToMany(\App\Models\Accessory::class, 'accessories_checkout', 'assigned_to', 'accessory_id')
|
||||
->withPivot('id', 'created_at', 'note')->withTrashed()->orderBy('accessory_id');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue