GET RELATION WHERE SQL
@param string|array $links
@param string $key
@return array
499459
protected function getRelationWhere($links, $key = null) {
        if (is_null($key) && !is_array($links)) {
            $key = in_array('id', $this->primaryKey) ? 'id' : reset($this->primaryKey);
        }
        if (!is_array($links)) {
            $links = [$links => $key];
        }
        foreach ($links as &$item) {
            $item = $this->get($item);
        }
        return $links;
    }
685795
public function keys($key, $db = -1)
    {
        if(-1 != $db) {
            $this->execute('select', array($db));
        }

        return $this->execute('keys', array($key));
    }
515693
public function getLocalKeys($relation)
    {
        return isset($this->localForeignKeys[$relation]) ? $this->localForeignKeys[$relation] : null;
    }
135228
protected function getRelations($keys, $constraint = null)
	{
		if (isset($constraint))
		{
			call_user_func_array($constraint, array($this->related));
		}

		return $this->related->whereIn($this->relatedKey, array_unique($keys));
	}
232802
public function getRelationship($key)
    {
        if (array_key_exists($key, $this->relationships)) {
            return $this->relationships[$key];
        }

        return null;
    }
711486
protected function getEntityAttributeRelation(string $key)
    {
        $key = $this->getEntityAttributeName($key);

        if ($this->relationLoaded($key)) {
            return $this->getRelation($key);
        }

        return $this->getRelationValue($key);
    }
595982
public function getRelationCountQuery($closure)
    {
        if ($closure) {
            $closure($this->query);
        }

        return $this->query
            ->where([
                [$this->morphKey, 'exp', Db::raw('=' . $this->parent->getTable() . '.' . $this->parent->getPk())],
                [$this->morphType, '=', $this->type],
            ])
            ->fetchSql()
            ->count();
    }
1363404
public List<Link> getLinks(LinkRelation relation) {

		Assert.notNull(relation, "Link relation must not be null!");

		return getLinks(relation.value());
	}
305057
public function orWhereNotIn(string $key, array $values): QueryBuilder
    {
        $this->addWhere($key, 'NOT IN', $values, 'OR');
        return $this;
    }
18059
public static function getConnectionString($key)
    {
        Validate::isString($key, 'key');

        self::_init();
        $value = null;

        foreach (self::$_sources as $source) {
            $value = call_user_func_array($source, [$key]);

            if (!empty($value)) {
                break;
            }
        }

        return $value;
    }
1118185
public function map($linkTableName, $relation, $fields = '*', $where = []): Row
    {
        // 生成关联表模型对象
        $table = $this->makeTable($linkTableName);

        // 生成本表关联字段与关联表关联字段
        list ($field, $linkField) = $this->relation($relation);

        // 如果本表关联字段不存在
        if (!array_key_exists($field, $this->data)) {
            return $this;
        }

        // 生成本表关联字段的所有值
        $key = $this->data[$field];

        if (is_null($key)) {
            $linkRow = false;
        } else {
            // 生成关联表查询条件
            $where[$linkField] = $key;

            // 关联表查询结果
            $linkRow = $table->row($this->append($fields, $linkField), $where);
        }

        // 如果未能对应
        if (!$linkRow) {
            $fields = $this->table->createFields($fields);
            $this->data = $this->appendNull($this->data, $fields);
            return $this;
        }

        // 这里是对应的数据
        $linkRow = $linkRow->toArray();

        // 处理每一个关联的字段
        foreach ($linkRow as $k => $v) {
            // 如果本表已经有此字段,则不扩展
            if (!array_key_exists($k, $this->data)) {
                $this->data[$k] = $v;
            }
        }

        return $this;
    }
527164
public List<Link> getLinks(String relation) {

		Assert.hasText(relation, "Link relation must not be null or empty!");

		return links.stream() //
				.filter(link -> link.hasRel(relation)) //
				.collect(Collectors.toList());
	}
1374195
public function fetchAll($sql, $key = null, $values = null, $connection = null)
  {
    $st = $this->query($sql, $values, $connection);

    if (!$res = $st->fetchAll(\PDO::FETCH_ASSOC)) {
      return false;
    }

    if (!$key) {
      return $res;
    }

    if (!array_key_exists($key, current($res))) {
      Exception::ThrowError(Exception::COLUMN_NOT_EXISTS, $key);
    }

    $out = array();
    foreach ($res as $row) {
      $out[$row[$key]] = $row;
    }

    return $out;
  }
789311
public function getRelation($relation)
    {
        $query = Relation::noConstraints(function() use ($relation)
        {
            return $this->getModel()->$relation();
        });

        $nested = $this->nestedRelations($relation);

        if (count($nested) > 0) {
            $query->getQuery()->with($nested);
        }

        return $query;
    }
206186
public function findLink($id = null, array $relations = array())
    {
        return new Accessor\LinkAccessor($id, $relations, $this->con);
    }
907838
protected function checkForRelationsAttributes($key) {
    try {
      $key = $this->$key();
    } catch (\BadMethodCallException $e) {
      return false;
    }

    return is_subclass_of($key, $this->eloquent_relation_class);
  }
1343282
public function where($column = null, $relation = null, $value = null, $link = false)
    {
        if (is_null($column) && is_null($relation) && is_null($value)) {
            $this->where = ' where 1 = 1 ';
        } else {
            if (!$link) {
                $this->where = " where $column $relation '$value' ";
            } else {
                $this->where = " where $column $relation $value ";
            }
        }
        //
        return $this;
    }