55
66class HasOne extends EloquentHasOne
77{
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+
838 /**
939 * Add the constraints for a relationship count query.
1040 *
@@ -14,9 +44,9 @@ class HasOne extends EloquentHasOne
1444 */
1545 public function getRelationCountQuery (Builder $ query , Builder $ parent )
1646 {
17- $ foreignKey = $ this ->getHasCompareKey ();
47+ $ foreignKey = $ this ->getForeignKeyName ();
1848
19- return $ query ->select ($ this -> getHasCompareKey ()) ->where ($ this -> getHasCompareKey () , 'exists ' , true );
49+ return $ query ->select ($ foreignKey ) ->where ($ foreignKey , 'exists ' , true );
2050 }
2151
2252 /**
@@ -33,16 +63,6 @@ public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*
3363
3464 $ key = $ this ->wrap ($ this ->getQualifiedParentKeyName ());
3565
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 );
4767 }
4868}
0 commit comments