find('first', [ 'recursive' => -1, 'conditions' => [ 'value' => $value ] ]); if (empty($existingValue)) { $this->create(); try { $this->save(['value' => $value]); return $this->id; } catch (Exception $e) { $existingValue = $this->find('first', [ 'recursive' => -1, 'conditions' => [ 'value' => $value ] ]); return $existingValue['ExistingValue']['id']; } } else { return $existingValue['CorrelationValue']['id']; } return false; } public function getValue($id) { $existingValue = $this->find('first', [ 'recursive' => -1, 'conditions' => [ 'id' => $id ] ]); if (!empty($existingValue)) { return $existingValue['CorrelationValue']['value']; } return false; } }