Skip to content

Instantly share code, notes, and snippets.

@akanehara
Last active December 23, 2015 10:19
Show Gist options
  • Save akanehara/6621103 to your computer and use it in GitHub Desktop.
Save akanehara/6621103 to your computer and use it in GitHub Desktop.
Yiiのアクティブレコード。問い合わせ上で導出できる論理属性の追加はこれじゃだめ?
<?php
/**
* @property float $x_of_pos
* @property float $y_of_pos
*/
class GlobalPosition
{
public $x_of_pos;
public $y_of_pos;
public function beforeFind()
{
parent::beforeFind();
$criteria = new CDbCriteria();
$criteria->select = "x(pos) AS x_of_pos, y(pos) AS y_of_pos";
$this->dbCriteria->mergeWith($criteria);
}
}
@akanehara
Copy link
Author

これ自体を直接findするときには問題ないけど、リレーションを辿ると機能しない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment