public function join($type, $model, $query = null) { if ($model instanceof Model and is_null($query)) { $query = new self(); $query->equal($this->from->field($this->from->pk()), $model->fk($this->from)); $query->from($model); } if ($model instanceof self) { $query = $model; } $this->joins[strtoupper($type)][] = $query; return $this; }