Created
December 13, 2012 18:40
-
-
Save fetus-hina/4278593 to your computer and use it in GitHub Desktop.
「Yii Framework の AR で関数通した結果を取得できないの?」とか言ってた結果現在こうなってる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Stations extends CActiveRecord { | |
public $distance; | |
// ^^^^^^^^^^^^^^^^^ | |
// (omit) | |
public function byLocation($lat, $long, $limit = 2000) { | |
$self = $this->getTableAlias(false, false); | |
$func = "distance({$self}.location, POINT(:latitude, :longitude))"; | |
$this->getDbCriteria()->mergeWith(array( | |
'select' => array('*', 'distance' => $func), | |
// ^^^^^^^^^^^^^^^^^^^^^ | |
'condition' => "{$func} <= :distance_limit", | |
'params' => array(':latitude' => (float)$lat, ':longitude' => (float)$long, ':distance_limit' => $limit), | |
'order' => "{$func} ASC", | |
)); | |
return $this; | |
} | |
// (omit) | |
} | |
?> | |
「プロパティ」にしてやれば CActiveRecord::populateRecord が見つけてなんとかしてくれる | |
が、この "scope" を使う時のためだけにこれを作るのはダサいと思うんだ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment