Skip to main content

has_one

One-to-one — the foreign key lives on the target table, pointing back at this one.

#[repository(table = "user")]
#[has_one(table = "profile")]
pub trait UserRepository: Repository {
// profile_bio → JOIN "profile" ON "profile".user_id = "user".id WHERE "profile".bio = $1 LIMIT 1
async fn first_by_profile_bio(&self, bio: String) -> sqlx::Result<Option<UserRow>>;
}

Unlike belongs_to, there's no FK-shortcut column here — even profile_id would JOIN, since there's no FK on user itself to resolve to (the FK lives on profile, pointing back).

See relations for the full attribute table and defaults.