Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/.meta-storm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<classMethod class="\Yiisoft\ActiveRecord\ActiveRecordInterface" method="hasProperty" argument="0">
<properties relatedTo="variable" />
</classMethod>
<classMethod class="\Yiisoft\ActiveRecord\ActiveRecordInterface" method="columnType" argument="0">
<classMethod class="\Yiisoft\ActiveRecord\ActiveRecordInterface" method="column" argument="0">
<properties relatedTo="variable" />
</classMethod>
</definitions>
Expand Down
6 changes: 4 additions & 2 deletions src/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\TableSchemaInterface;

use function array_diff_key;
Expand Down Expand Up @@ -84,9 +85,10 @@ public function propertyNames(): array
return $this->tableSchema()->getColumnNames();
}

public function columnType(string $propertyName): string
public function column(string $propertyName): ColumnInterface
{
return $this->tableSchema()->getColumn($propertyName)?->getType() ?? ColumnType::STRING;
return $this->tableSchema()->getColumn($propertyName)
?? $this->db()->getColumnFactory()->fromType(ColumnType::STRING, ['name' => $propertyName]);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/ActiveRecordInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Throwable;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Exception\Exception;
use InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidCallException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Schema\Column\ColumnInterface;

/**
* @psalm-import-type ModelClass from ActiveQuery
Expand All @@ -27,11 +27,9 @@ interface ActiveRecordInterface
public function propertyNames(): array;

/**
* Returns the abstract type of the property.
*
* @psalm-return ColumnType::*
* @return ColumnInterface The column instance of the property.
*/
public function columnType(string $propertyName): string;
public function column(string $propertyName): ColumnInterface;

/**
* Create {@see ActiveQueryInterface} instance for the given model class.
Expand Down
6 changes: 4 additions & 2 deletions src/ActiveRelationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Yiisoft\Db\Exception\Exception;
use InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Expression\ArrayExpression;
use Yiisoft\Db\QueryBuilder\Condition\In;
use Yiisoft\Db\QueryBuilder\Condition\ArrayOverlaps;
use Yiisoft\Db\QueryBuilder\Condition\JsonOverlaps;
Expand Down Expand Up @@ -569,9 +570,10 @@ protected function filterByModels(array $models): void
$columnName = reset($columnNames);
/** @var string $propertyName */
$propertyName = array_key_first($this->link);
$column = $this->getModel()->column($propertyName);

match ($this->getModel()->columnType($propertyName)) {
ColumnType::ARRAY => $this->andWhere(new ArrayOverlaps($columnName, $values)),
match ($column->getType()) {
ColumnType::ARRAY => $this->andWhere(new ArrayOverlaps($columnName, new ArrayExpression($values, $column))),
ColumnType::JSON => $this->andWhere(new JsonOverlaps($columnName, $values)),
default => $this->andWhere(new In($columnName, $values)),
};
Expand Down
4 changes: 0 additions & 4 deletions tests/Support/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public static function inaccessibleProperty(object $object, string $propertyName
if ($propertyName !== '') {
$property = $class->getProperty($propertyName);

$property->setAccessible(true);

/** @psalm-var mixed $result */
$result = $property->getValue($object);
}
Expand All @@ -69,8 +67,6 @@ public static function invokeMethod(object $object, string $method, array $args
if ($method !== '') {
$method = $reflection->getMethod($method);

$method->setAccessible(true);

/** @psalm-var mixed $result */
$result = $method->invokeArgs($object, $args);
}
Expand Down
Loading