# `data.lookup_not_unique`

Code looks a record up by an email field that isn't `unique: true` across the whole table, so an address could find several.

Area 15, [Personal data](/docs/personal-data.md); not declinable; the next step is usually the human's.

## Why Jadpo refuses it

A lookup gives one record or none. If several records could hold one
address, which came back would show more than one person's. So the field
must be `unique: true`, and its entity one every tenant shares: a
tenant's unique rule holds only within the tenant, so two tenants'
records may hold the same address.

## What it looks like

main.jadpo:

```jadpo
principal {
    user: {
        subject: Member.handle
    }
}

authentication {
    api_token: {}
}

policy {
    actions: {
        has_account: [Access.authenticated]
    }
}

type Handle = Text {
    max_length: 40
}

type AddressStanding = Enum {
    account_held
    no_account
}

entity Member {
    id: Uuid
    handle: Handle {
        unique: true
    }
    email: Email

    policy: {
        create: [Access.public]
        read: [id]
    }
}

/// Whether an address has an account.
action has_account(email: Member.email) -> AddressStanding {
    match Member.lookup(email: email) {
        none -> {
            return AddressStanding.no_account
        }
        some -> {
            return AddressStanding.account_held
        }
    }
}
```

```text
error: `Member.lookup` finds by `email`, which isn't `unique: true`
 --> main.jadpo:41:25
   |
41 |     match Member.lookup(email: email) {
   |                         ^^^^^ not unique
  reason: A lookup gives one record or none. Without `unique: true` several `Member` records could hold one address, and which came back would show more than one person's.
  next: Make `Member.email` `unique: true`, if one address is one person's (human)
  rule: data.lookup_not_unique
  help: https://jadpo.dev/docs/errors/data.lookup_not_unique

check failed: 1 error, 1 file
```

`(human)` at the end of the `next:` line tells your coding agent to stop
and ask you which fix you want, because the choice is yours to make: it
decides whether two of your records may share an address.

## How to fix it

**If one address is one person's**, make the field `unique: true`:

```jadpo
    email: Email {
        unique: true
    }
```


Two members can no longer share an address, and the lookup finds the one
who has it, or none.

## Related

- [Looking up one person by email](/docs/looking-up-one-person-by-email.md)
- [A unique rule holds within its tenant](/docs/tenancy.md#a-unique-rule-holds-within-its-tenant)
