_tableName_ = 'points'; parent::__construct($fromArray); $this->setRelation('category', 'categoryId', 'Category', 'id', self::TO_ONE); $this->setRelation('authorUser', 'author', 'User', 'id', self::TO_ONE); $this->setRelation('photos', 'id', 'Photo', 'pointId', self::TO_MANY); } static function model() { return new self(); } public function getImg() { $img = $this->img; if ($img == '') { $img = array_shift($this->photos); $img = '/photos/middle/' . $img->name; } return $img; } }