New models for node and location admin pages.

This commit is contained in:
Dane Everitt 2017-02-03 16:50:28 -05:00
parent 96d3aa767f
commit 09d23deed6
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
10 changed files with 152 additions and 78 deletions

View file

@ -48,8 +48,8 @@ class Allocation extends Model
* @var array
*/
protected $casts = [
'node' => 'integer',
'node_id' => 'integer',
'port' => 'integer',
'assigned_to' => 'integer',
'server_id' => 'integer',
];
}

View file

@ -226,4 +226,24 @@ class Node extends Model
{
return $this->hasOne(Location::class, 'id', 'location_id');
}
/**
* Gets the servers associated with a node.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function servers()
{
return $this->hasMany(Server::class);
}
/**
* Gets the allocations associated with a node.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function allocations()
{
return $this->hasMany(Allocation::class);
}
}

View file

@ -121,7 +121,7 @@ class Server extends Model
'services.name as a_serviceName',
'service_options.name as a_serviceOptionName'
)->join('nodes', 'servers.node_id', '=', 'nodes.id')
->join('locations', 'nodes.location', '=', 'locations.id')
->join('locations', 'nodes.location_id', '=', 'locations.id')
->join('services', 'servers.service_id', '=', 'services.id')
->join('service_options', 'servers.option_id', '=', 'service_options.id')
->join('allocations', 'servers.allocation_id', '=', 'allocations.id');
@ -218,6 +218,16 @@ class Server extends Model
return Javascript::put($response);
}
/**
* Gets the user who owns the server.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function user()
{
return $this->hasOne(User::class, 'id', 'owner_id');
}
/**
* Gets all allocations associated with this server.
*
@ -225,7 +235,7 @@ class Server extends Model
*/
public function allocations()
{
return $this->hasMany(Allocation::class, 'assigned_to');
return $this->hasMany(Allocation::class, 'server_id');
}
/**