ActiveRecord\Table::find_by_sql PHP Method

find_by_sql() public method

public find_by_sql ( $sql, $values = null, $readonly = false, $includes = null )
    public function find_by_sql($sql, $values = null, $readonly = false, $includes = null)
    {
        $this->last_sql = $sql;
        $collect_attrs_for_includes = is_null($includes) ? false : true;
        $list = $attrs = array();
        $sth = $this->conn->query($sql, $this->process_data($values));
        $self = $this;
        while ($row = $sth->fetch()) {
            $cb = function () use($row, $self) {
                return new $self->class->name($row, false, true, false);
            };
            if ($this->cache_individual_model) {
                $key = $this->cache_key_for_model(array_intersect_key($row, array_flip($this->pk)));
                $model = Cache::get($key, $cb, $this->cache_model_expire);
            } else {
                $model = $cb();
            }
            if ($readonly) {
                $model->readonly();
            }
            if ($collect_attrs_for_includes) {
                $attrs[] = $model->attributes();
            }
            $list[] = $model;
        }
        if ($collect_attrs_for_includes && !empty($list)) {
            $this->execute_eager_load($list, $attrs, $includes);
        }
        return $list;
    }