mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 15:02:47 +08:00
hasOne关联的has方法改进
This commit is contained in:
@@ -67,11 +67,14 @@ class HasOne extends OneToOne
|
|||||||
public function has()
|
public function has()
|
||||||
{
|
{
|
||||||
$table = $this->query->getTable();
|
$table = $this->query->getTable();
|
||||||
|
$model = basename(str_replace('\\', '/', get_class($this->parent)));
|
||||||
|
$relation = basename(str_replace('\\', '/', $this->model));
|
||||||
$localKey = $this->localKey;
|
$localKey = $this->localKey;
|
||||||
$foreignKey = $this->foreignKey;
|
$foreignKey = $this->foreignKey;
|
||||||
return $this->parent->db()->alias('a')
|
return $this->parent->db()
|
||||||
->whereExists(function ($query) use ($table, $localKey, $foreignKey) {
|
->alias($model)
|
||||||
$query->table([$table => 'b'])->field('b.' . $foreignKey)->whereExp('a.' . $localKey, '=b.' . $foreignKey);
|
->whereExists(function ($query) use ($table, $model, $relation, $localKey, $foreignKey) {
|
||||||
|
$query->table([$table => $relation])->field($relation . '.' . $foreignKey)->whereExp($model . '.' . $localKey, '=' . $relatoin . '.' . $foreignKey);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user