| @@ 57-81 (lines=25) @@ | ||
| 54 | * @param string|null $toScenario | |
| 55 | * @return ModelWithId|null | |
| 56 | */ | |
| 57 | public function findById(int $id, string $toScenario = null) | |
| 58 |     { | |
| 59 | ||
| 60 | // Check cache | |
| 61 |         if (!$model = $this->findCacheById($id)) { | |
| 62 | ||
| 63 | // Find record in db | |
| 64 |             if ($record = $this->findRecordById($id)) { | |
| 65 | ||
| 66 | $model = $this->findByRecord($record, $toScenario); | |
| 67 | ||
| 68 |             } else { | |
| 69 | ||
| 70 | $this->_cacheById[$id] = null; | |
| 71 | ||
| 72 | return null; | |
| 73 | ||
| 74 | } | |
| 75 | ||
| 76 | } | |
| 77 | ||
| 78 | return $model; | |
| 79 | ||
| 80 | } | |
| 81 | ||
| 82 | /** | |
| 83 | * @param int $id | |
| 84 | * @param string|null $toScenario | |
| @@ 51-78 (lines=28) @@ | ||
| 48 | * @param string|null $toScenario | |
| 49 | * @return BaseObject|null | |
| 50 | */ | |
| 51 | public function findById(int $id, string $toScenario = null) | |
| 52 |     { | |
| 53 | ||
| 54 | // Check cache | |
| 55 |         if (!$object = $this->findCacheById($id)) { | |
| 56 | ||
| 57 | // Find record in db | |
| 58 | if ($record = $this->findRecordByCondition( | |
| 59 | ['id' => $id] | |
| 60 | ) | |
| 61 |             ) { | |
| 62 | ||
| 63 | // Perhaps in cache | |
| 64 | $object = $this->findByRecord($record, $toScenario); | |
| 65 | ||
| 66 |             } else { | |
| 67 | ||
| 68 | $this->_cacheById[$id] = null; | |
| 69 | ||
| 70 | return null; | |
| 71 | ||
| 72 | } | |
| 73 | ||
| 74 | } | |
| 75 | ||
| 76 | return $object; | |
| 77 | ||
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * @param int $id | |