Find Record by Primary Key Id.

@param $arguments

@return $this|mixed
481241
public function findByPK($arguments)
    {
        $arguments = (array) $arguments;

        $args = [
            'primaryKey' => $this->getKeyName(),
            'args'       => $arguments,
        ];

        $fetch = $this->queryBuilder()->find('find', $args);

        if ($fetch instanceof Collection && empty($fetch->asArray())) {
            return $this->returnEmptyObject();
        }

        $this->setId($this->getKeyName(), array_shift($arguments));
        $this->{$this->getKeyName()} = $fetch[0]->{$this->getKeyName()};

        foreach ($fetch[0]->getAttributes() as $key => $value) {
            $this->{$key} = $value;
        }

        $this->assignPropertiesToModel($this->attributes);

        return $this;
    }
438511
public function whereKey($id)
    {
        if (is_array($id) || $id instanceof Arrayable) {
            $this->query->whereIn($this->model->getQualifiedKeyName(), $id);

            return $this;
        }

        return $this->where($this->model->getQualifiedKeyName(), '=', $id);
    }
431044
public function findByGroup($keys, $initial, $reduce, $conditions, $get_all_info=false) {
        return $this->db->group($this->table, $keys, $initial, $reduce, $conditions, $get_all_info);
    }
725231
public function joinWith($arguments)
    {
        $class = static::model();

        $tableWith = Inflector::tabilize($arguments[0]);

        $params = [
            $class->tableName.'.'.$class->primaryKey,
            '=',
            $tableWith.'.'.Inflector::singularize($class->tableName).self::DEFAULT_FOREIGN_KEY_SUFFIX,
        ];

        if (isset($arguments[1])) {
            $params = $arguments[1];
        }

        return $this->queryBuilder()->leftOuterJoin($tableWith, $params, $arguments[2]);
    }
228667
public function count(...$arguments): ?int
    {
        $where       = $arguments[0] ?? null;
        $whereParams = $arguments[1] ?? null;

        $query = $this->initQueryBuilder();
        try {
            $query->select('1');

            if ($where != null) {
                $query->where($where, $whereParams);
            }

            return $query->count();
        } catch (\Exception $e) {
            $this->setFail($e);

            return null;
        }
    }
260480
public final function findOne($id, $fields = '*') {
        if (is_array($id)) {
            $where = $id;
        } else {
            $idf   = $this->primaryKey;
            $where = [$idf => $id];
        }
        if (is_array($fields)) {
            $sql = $this->select(...$fields);
        } else {
            $sql = $this->select($fields);
        }
        $sql->where($where)->limit(0, 1);

        return $sql;
    }
592027
protected function addMany(array $arguments = [])
    {
        foreach ($arguments as $name => $options) {
            $this->add($name, $options);
        }
    }
1283750
public function removeArguments(array $arguments = null)
  {
    if ($this->isLocked()) {
      return $this->getObj()->removeArguments($arguments)->setLocked();
    } else {
      return parent::removeArguments($arguments);
    }
  }
889834
public static function instanceFromArguments($arguments = []) {
        $arguments = array_values($arguments);
        $argumentsCount = count($arguments);
        for ($i = 0; $i < $argumentsCount; $i++) {
            if (is_object($arguments[$i]) && $arguments[$i] instanceof SharedDataInterface) {
                return $arguments[$i];
            }
        }
        return null;
    }
82972
public static function find($args = false)
    {
        /* @var ActiveRecord $model */

        $query = null;
        $model = new static();

        if ($args && $args instanceof Query) {
            $query = $args;
            $query->limit = 1;

            if (empty($query->from)) {
                $query->addFrom($model->getTableName().' T');
            }
        } elseif ($args && is_array($args)) {
            $args['limit'] = 1;
            if (!isset($args['from'])) {
                $args['from'] = $model->getTableName().' T';
            }
            $query = new Query($args);
        } elseif (!$args) {
            $query = new Query(
                [
                    'from' => $model->getTableName().' T',
                    'limit' => 1,
                ]
            );
        } else {
            throw new Exception(translate('Bad arguments'), 500, Exception::BADARGUMENTS);
        }

        $stmt = $model->getDB()->prepare($query->toSql());
        $stmt->execute($query->params);
        $record = $stmt->fetchObject(get_class($model), [false]);
        $stmt->closeCursor();

        return $record;
    }
214701
public function or(...$arguments): self
    {
        $op = self::OP_OR;

        // just update last where op
        if (isset($this->query['where'])) {
            $this->query['where'][count($this->query['where']) - 1][1] = $op;
        }

        if (empty($arguments)) return $this;

        $query = $arguments[0] ?? null;
        $queryParams = $arguments[1] ?? null;

        return $this->where($query, $queryParams, $op);
    }
122363
public function add(...$arguments): QueryBuilderInterface
    {
        if ($this->node instanceof ObjectNode) {
            return $this->addToObjectNode(...$arguments);
        }

        return $this->addToArrayNode(...$arguments);
    }
1150025
public function setArguments(array $arguments)
    {
        foreach ($arguments as $arg) {
            if (!is_scalar($arg)) {
                $type = gettype($arg);
                throw new DomainException("Arguments array should be an array of scalar, but found $type");
            }
        }

        $this->arguments = $arguments;

        return $this;
    }
288002
public function query($id, $method, array $arguments = null)
    {
        $this->client->query($id, $method, $arguments);

        return $this;
    }
396928
public function where(...$args): self
    {
        $this->createToken('AND', $args, $this->whereTokens, $this->whereWrapper());

        return $this;
    }
261175
protected function getKeyArguments($arguments)
    {
        $keys = [];
        foreach ($arguments as $argument) {
            if (is_array($argument)) {
                $keys = array_merge($keys, $this->getKeyArguments($argument));
            }
            if (is_string($argument)) {
                $keys = array_merge($keys, $this->parseKeysString($argument));
            }
        }

        return $keys;
    }
106884
public function where($arguments)
	{

		//put this in try...catch block for better error handling
		try{

			//throw exception if argument pairs do ot match
			if ( is_float( sizeof($arguments) / 2 ) ) 
			{
				//throw exception
				throw new MySQLException("No arguments passed for the where clause");

			}
			
		}

		//diplay error message
		catch(MySQLException $MySQLExceptionObject){

			//display error message
			$MySQLExceptionObject->errorShow();

		}


		//check if only one argument pair was passed'
		if ( sizeof($arguments) == 2) 
		{
			//get first argument and replace ? with a placeholder
			$arguments[0] = preg_replace("#\?#", "%s", $arguments[0]);

			//quote the argument content
			$arguments[1] = $this->quote($arguments[1]);

			//populate the wheres array
			$this->wheres[] = call_user_func_array("sprintf", $arguments);

			//return this object instance
			return $this;	


		}

		//there are multiple argument supplied
		else
		{
			//get the number of iterations 
			$count = sizeof($arguments) / 2;

			//loop through number of iterations population the wheres array
			for ($i = 0; $i < $count; $i++ ) 
			{ 
				//get the batch of array to work with
				$argumentsPair  = array_splice($arguments, 0, 2);

				//get first argument and replace ? with a placeholder
				$argumentsPair[0] = preg_replace("#\?#", "%s", $argumentsPair[0]);

				//quote the argument content
				$argumentsPair[1] = $this->quote($argumentsPair[1]);
				
				//populate the wheres array
				$this->wheres[] = call_user_func_array("sprintf", $argumentsPair);

			}

			//return this object instance
			return $this;	

		}
		
	}