Skip to content

Commit

Permalink
WIP: CodeIgniter4 Orm
Browse files Browse the repository at this point in the history
  • Loading branch information
agungsugiarto committed Aug 6, 2021
1 parent 841431f commit 663e190
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
21 changes: 11 additions & 10 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,8 @@ protected function callScope(callable $scope, array $parameters = [])
// scope so that we can properly group the added scope constraints in the
// query as their own isolated nested where statement and avoid issues.
$originalWhereCount = is_null($query->getCompiledQBWhere())
? 0 : count($query->getCompiledQBWhere());
? 0
: count($query->getCompiledQBWhere());

$result = $scope(...array_values($parameters)) ?? $this;

Expand Down Expand Up @@ -1453,12 +1454,12 @@ protected function groupWhereSliceForScope(BaseBuilder $query, $whereSlice)
// booleans and in this case create a nested where expression. That way
// we don't add any unnecessary nesting thus keeping the query clean.
if ($whereBooleans->contains('or')) {
$query->wheres[] = $this->createNestedWhere(
(fn () => $this->QBWhere[] = $this->createNestedWhere(
$whereSlice,
$whereBooleans->first()
);
))->call($query);
} else {
$query->wheres = array_merge($query->getCompiledQBWhere(), $whereSlice);
(fn () => $this->QBWhere = array_merge($query->getCompiledQBWhere(), $whereSlice))->call($query);
}
}

Expand Down Expand Up @@ -1555,10 +1556,10 @@ protected function parseWithRelations(array $relations)
$name = $constraints;

[$name, $constraints] = Str::contains($name, ':')
? $this->createSelectWithConstraint($name)
: [$name, static function () {
//
}];
? $this->createSelectWithConstraint($name)
: [$name, static function () {
//
}];
}

// We need to separate out any nested includes, which allows the developers
Expand Down Expand Up @@ -1587,8 +1588,8 @@ protected function createSelectWithConstraint($name)
}

return $query instanceof BelongsToMany
? $query->getRelated()->getTable().'.'.$column
: $column;
? $query->getRelated()->getTable().'.'.$column
: $column;
}, explode(',', explode(':', $name)[1])));
}];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/BuildsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function prepareValueAndOperator($value, $operator, $useDefault = false)
*/
public function toSql()
{
return $this->query->getCompiledSelect();
return $this->toBase()->getCompiledSelect();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/ExplainsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function explain()
{
$sql = $this->toSql();

$bindings = $this->getBindings();
$bindings = $this->query->getBinds();

$explanation = $this->getConnection()->select('EXPLAIN ' . $sql, $bindings);
$explanation = $this->fromQuery('EXPLAIN ' . $sql, $bindings);

return new Collection($explanation);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
}

if ($attributes[$key] && $this->isCustomDateTimeCast($value)) {
$attributes[$key] = $attributes[$key]->format(explode(':', $value, 2)[1]);
$attributes[$key] = $attributes[$key]->translatedFormat(explode(':', $value, 2)[1]);
}

if (
Expand Down

0 comments on commit 663e190

Please sign in to comment.