
Cakephp2での仮想フィールドは、SQL関数を記述しておくと実行結果が取得できていましたが、Cakephp4では、仮想フィールドは存在するものの、SQL関数は文字列として扱われるため、そのままでは実行されません。また、仮想フィールドを利用するのに、ひと手間必要なので、シンプルに$this->find()->select() 内にて、そのまま実行させる方がはるかにシンプルで簡単です。
例えば、Cakephp2で$virtualFieldsが定義されていたとします。
class Hoge extends AppModel
{
public $virtualFields = [
'url' => 'CONCAT("https://hoge.jp", path)',
];
}
Cakephp4への移行時は、直接$this->find()->select()で書きます。
public function getHoge($path): array
{
$query = $this->find()
->select(['url' => 'CONCAT("https://hoge.jp", path)']);
}
Cakephp4: 仮想フィールド(プロパティ)
https://book.cakephp.org/4/ja/orm/entities.html#entities-virtual-fields