public function actionDelete($userId, $friendId) { $friendship = Friendship::findOne(['user_id' => $userId, 'friend_id' => $friendId]); if ($friendship === null) { throw new Exception('Friendship was not found'); } $friendshipSummary = $friendship->jsonSummary; $transaction = Yii::$app->db->beginTransaction(); try { // Mutuality update is handled in Friendship EVENT_AFTER_DELETE if (!$friendship->delete()) { throw new DbException('Could not delete friendship'); } $transaction->commit(); } catch (Exception $exception) { $transaction->rollBack(); throw $exception; } return $friendshipSummary; }
public function getRelatedFriendship() { $relatedFriendship = Friendship::findOne(['user_id' => $this->friend_id, 'friend_id' => $this->user_id]); return $relatedFriendship; }