Schema for two-way mutual connection relationships.
Represents a bidirectional relationship that requires acceptance from both parties. Similar to LinkedIn connections or Facebook friend requests.
Status Flow
pending- Request sent, awaiting responseaccepted- Both parties have agreed to connectrejected- Recipient declined the request
Fields
requester_uuid- UUID of the user who initiated the connection requestrecipient_uuid- UUID of the user who received the requeststatus- Current status of the connectionrequested_at- When the request was sentresponded_at- When the recipient responded (nil if pending)
Examples
# Pending connection request
%Connection{
uuid: "018e3c4a-9f6b-7890-abcd-ef1234567890",
requester_uuid: "019abc12-3456-7890-abcd-ef1234567890",
recipient_uuid: "019abc12-9876-5432-abcd-ef1234567890",
status: "pending",
requested_at: ~N[2025-01-15 10:30:00],
responded_at: nil
}
# Accepted connection
%Connection{
uuid: "018e3c4a-9f6b-7890-abcd-ef1234567890",
requester_uuid: "019abc12-3456-7890-abcd-ef1234567890",
recipient_uuid: "019abc12-9876-5432-abcd-ef1234567890",
status: "accepted",
requested_at: ~N[2025-01-15 10:30:00],
responded_at: ~N[2025-01-15 11:00:00]
}Business Rules
- Cannot connect with yourself
- Cannot connect if blocked (either direction)
- If A requests B while B has pending request to A -> auto-accept both
- Only one active connection per user pair
Summary
Functions
Returns whether this connection is accepted.
Changeset for creating a new connection request.
Returns whether this connection is pending.
Returns whether this connection is rejected.
Changeset for updating connection status (accept/reject).
Returns the list of valid statuses.
Types
@type status() :: String.t()
@type t() :: %PhoenixKit.Modules.Connections.Connection{ __meta__: term(), inserted_at: DateTime.t() | nil, recipient: PhoenixKit.Users.Auth.User.t() | Ecto.Association.NotLoaded.t(), recipient_uuid: UUIDv7.t(), requested_at: DateTime.t(), requester: PhoenixKit.Users.Auth.User.t() | Ecto.Association.NotLoaded.t(), requester_uuid: UUIDv7.t(), responded_at: DateTime.t() | nil, status: status(), updated_at: DateTime.t() | nil, uuid: UUIDv7.t() | nil }
Functions
Returns whether this connection is accepted.
Changeset for creating a new connection request.
Required Fields
requester_uuid- UUID of the user sending the requestrecipient_uuid- UUID of the user receiving the request
Validation Rules
- Both user UUIDs are required
- Cannot request connection with yourself
- Status must be valid
Returns whether this connection is pending.
Returns whether this connection is rejected.
Changeset for updating connection status (accept/reject).
Returns the list of valid statuses.