primaryModel instanceof Account && $this->link === ['owner_id' => 'id']) { $this->primaryModel->id = (string)$this->primaryModel->id; $idHasBeenCastedToString = true; } $query = parent::prepare($builder); if ($idHasBeenCastedToString) { $this->primaryModel->id = (int)$this->primaryModel->id; } return $query; } }