Skip to content

Commit b138926

Browse files
committed
Use belongsTo versus hasOne when more logical.
1 parent 323f1d9 commit b138926

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

app/Models/Database.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ class Database extends Model
6262
/**
6363
* Gets the host database server associated with a database.
6464
*
65-
* @return \Illuminate\Database\Eloquent\Relations\HasOne
65+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
6666
*/
6767
public function host()
6868
{
69-
return $this->hasOne(DatabaseServer::class, 'id', 'db_server');
69+
return $this->belongsTo(DatabaseServer::class, 'db_server');
7070
}
7171

7272
/**
7373
* Gets the server associated with a database.
7474
*
75-
* @return \Illuminate\Database\Eloquent\Relations\HasOne
75+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
7676
*/
7777
public function server()
7878
{
79-
return $this->hasOne(Server::class, 'id', 'server_id');
79+
return $this->belongsTo(Server::class);
8080
}
8181
}

app/Models/DatabaseServer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ class DatabaseServer extends Model
6363
/**
6464
* Gets the node associated with a database host.
6565
*
66-
* @return \Illuminate\Database\Eloquent\Relations\HasOne
66+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
6767
*/
6868
public function node()
6969
{
70-
return $this->hasOne(Node::class, 'id', 'linked_node');
70+
return $this->belongsTo(Node::class, 'linked_node');
7171
}
7272
}

app/Models/Node.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ public function getConfigurationAsJson($pretty = false)
220220
/**
221221
* Gets the location associated with a node.
222222
*
223-
* @return \Illuminate\Database\Eloquent\Relations\HasOne
223+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
224224
*/
225225
public function location()
226226
{
227-
return $this->hasOne(Location::class, 'id', 'location_id');
227+
return $this->belongsTo(Location::class);
228228
}
229229

230230
/**

app/Models/Server.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ public function js($additional = null, $overwrite = null)
221221
/**
222222
* Gets the user who owns the server.
223223
*
224-
* @return \Illuminate\Database\Eloquent\Relations\HasOne
224+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
225225
*/
226226
public function user()
227227
{
228-
return $this->hasOne(User::class, 'id', 'owner_id');
228+
return $this->belongsTo(User::class, 'owner_id');
229229
}
230230

231231
/**
@@ -251,21 +251,21 @@ public function pack()
251251
/**
252252
* Gets information for the service associated with this server.
253253
*
254-
* @return \Illuminate\Database\Eloquent\Relations\HasOne
254+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
255255
*/
256256
public function service()
257257
{
258-
return $this->hasOne(Service::class, 'id', 'service_id');
258+
return $this->belongsTo(Service::class);
259259
}
260260

261261
/**
262262
* Gets information for the service option associated with this server.
263263
*
264-
* @return \Illuminate\Database\Eloquent\Relations\HasOne
264+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
265265
*/
266266
public function option()
267267
{
268-
return $this->hasOne(ServiceOptions::class, 'id', 'option_id');
268+
return $this->belongsTo(ServiceOptions::class);
269269
}
270270

271271
/**
@@ -281,11 +281,11 @@ public function variables()
281281
/**
282282
* Gets information for the node associated with this server.
283283
*
284-
* @return \Illuminate\Database\Eloquent\Relations\HasOne
284+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
285285
*/
286286
public function node()
287287
{
288-
return $this->hasOne(Node::class, 'id', 'node_id');
288+
return $this->belongsTo(Node::class);
289289
}
290290

291291
/**

0 commit comments

Comments
 (0)