_tableName_ = 'trips'; parent::__construct($fromArray); $this->setRelation('tracks', 'id', 'Tracks', 'tripId', self::TO_MANY, '`id` ASC'); } static function model() { return new self(); } function distance() { return Geo::formatedDistance($this->distance); } /** * Считает/пересчитывает длину трека и всех его фрагментов */ function calculateDist() { $tracks = $this->tracks; $distance = 0; foreach ($tracks as $track) { $distance += $track->calculateDist(); } $this->distance = $distance; $this->save(); return $distance; } }