5
5
6
6
class HasOne extends EloquentHasOne
7
7
{
8
+ /**
9
+ * Get the key for comparing against the parent key in "has" query.
10
+ *
11
+ * @return string
12
+ */
13
+ public function getForeignKeyName ()
14
+ {
15
+ return $ this ->foreignKey ;
16
+ }
17
+
18
+ /**
19
+ * Get the key for comparing against the parent key in "has" query.
20
+ *
21
+ * @return string
22
+ */
23
+ public function getHasCompareKey ()
24
+ {
25
+ return $ this ->getForeignKeyName ();
26
+ }
27
+
28
+ /**
29
+ * @inheritdoc
30
+ */
31
+ public function getRelationExistenceQuery (Builder $ query , Builder $ parentQuery , $ columns = ['* ' ])
32
+ {
33
+ $ foreignKey = $ this ->getForeignKeyName ();
34
+
35
+ return $ query ->select ($ foreignKey )->where ($ foreignKey , 'exists ' , true );
36
+ }
37
+
8
38
/**
9
39
* Add the constraints for a relationship count query.
10
40
*
@@ -14,9 +44,9 @@ class HasOne extends EloquentHasOne
14
44
*/
15
45
public function getRelationCountQuery (Builder $ query , Builder $ parent )
16
46
{
17
- $ foreignKey = $ this ->getHasCompareKey ();
47
+ $ foreignKey = $ this ->getForeignKeyName ();
18
48
19
- return $ query ->select ($ this -> getHasCompareKey ()) ->where ($ this -> getHasCompareKey () , 'exists ' , true );
49
+ return $ query ->select ($ foreignKey ) ->where ($ foreignKey , 'exists ' , true );
20
50
}
21
51
22
52
/**
@@ -33,16 +63,6 @@ public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*
33
63
34
64
$ key = $ this ->wrap ($ this ->getQualifiedParentKeyName ());
35
65
36
- return $ query ->where ($ this ->getHasCompareKey (), 'exists ' , true );
37
- }
38
-
39
- /**
40
- * Get the plain foreign key.
41
- *
42
- * @return string
43
- */
44
- public function getPlainForeignKey ()
45
- {
46
- return $ this ->getForeignKey ();
66
+ return $ query ->where ($ this ->getForeignKeyName (), 'exists ' , true );
47
67
}
48
68
}
0 commit comments