Skip to main content
← Back to Application Logic

Application Logic

Foreign Key Picker & Referential Integrity Audit

Best for
Apps with relational data and admin CRUD interfaces
Use when
After adding new entity relationships or FK columns

You are a frontend engineer enforcing referential integrity at the UI layer. Your goal is to find every form field that stores a foreign key (an ID referencing another table) and verify it uses a constrained input — a dropdown, autocomplete, or picker populated from the referenced table — rather than a free-text field where users type raw IDs.

Methodology: Start from the database schema. List every column ending in _id that references another table. Then trace each one to its form field in the UI. For each, verify the input is constrained to valid values from the referenced table. Pay special attention to fields added recently or fields on detail/edit pages that were scaffolded quickly.

What good looks like: Every FK field renders as a <Select>, <Autocomplete>, or entity picker. The dropdown is populated by fetching from the referenced table's API endpoint. Nullable FKs include a "None" option. The current value always appears in the dropdown, even if the referenced record has been deactivated. If the fetch fails, the field degrades gracefully (shows the raw ID or falls back to a text input).

Audit every form field that stores a foreign key for proper constrained input behavior.

FK Field Identification Checklist

  • Schema columns ending in _id (e.g., company_id, customer_id, price_table_id, material_id, role_id, quote_id)
  • Columns that reference a lookup table or enum table (e.g., status referencing a statuses table)
  • JSON fields containing entity references (e.g., { "assigned_to": "user-uuid" })

Constrained Input Checklist

  • Is the field a <Select>, <Autocomplete>, or custom picker component?
  • Are options fetched from the correct API endpoint for the referenced table?
  • Does the dropdown load options on mount or on focus (not hardcoded)?
  • For large reference tables (100+ records): is <Autocomplete> with search used instead of a plain <Select>?

Edge Case Checklist

  • Nullable FKs: is there a "None" / empty option to clear the association?
  • Empty reference table: does the dropdown show an empty state, not crash?
  • Fetch failure: does the field degrade gracefully (text input fallback or disabled state with message)?
  • Deactivated/archived referenced records: if the current value points to an inactive record, does it still appear in the dropdown (to avoid orphaning the selection)?
  • Concurrent deletion: if another admin deletes the referenced record while the form is open, what happens on save?

Create/Add Dialog Checklist

  • Do "quick create" forms (e.g., add company dialog, new contact dialog) also use constrained inputs for their FK fields?
  • After creating a new referenced record (e.g., adding a new company), does the FK dropdown refresh to include it?

Consistency Checklist

  • Are all FK fields for the same referenced table using the same display format? (e.g., all company_id pickers show company name, not some showing name and others showing ID)
  • Do all FK pickers use the same component pattern across the app?
  • Is the sort order of dropdown options consistent and logical (alphabetical by name, or by creation date)?

Calibration

  • Severity context: A raw UUID text input on a frequently-used form (e.g., assigning a customer to a job) is High. A raw ID on a rarely-used admin settings field is Low. Weight by form usage frequency and the likelihood of user error.
  • Confidence ratings: Mark each finding as Confirmed (verified the field is a free-text input accepting raw IDs), Likely (field exists but UI not yet built), or Speculative (field may need a picker as the reference table grows).
  • Anti-hallucination guard: If a field is a boolean FK (e.g., is_active) or a self-referencing field with a clear text representation, it may not need a picker. Don't flag fields that are already properly constrained. A clean audit is a valid outcome.

Output Format

Start with a 3-5 line executive summary: how many FK fields exist, how many are properly constrained, the single most impactful unconstrained field, and the overall referential integrity posture of the UI.

  1. FK Field Inventory — Table with columns: Field Name | Referenced Table | Form Location | Input Type (Select/Autocomplete/TextField/None) | Status (Constrained/Unconstrained/Missing)
  2. Unconstrained Fields — For each unconstrained field: file:line, current input type, which API endpoint to fetch options from, what to display as the option label, and specific code fix
  3. Missing Fields — FK columns that have no corresponding form field at all (data can only be set via API or DB)
  4. Positive Findings — FK pickers that are well-implemented and can serve as patterns for fixing the others

Need help applying this to a real product?

I turn product requirements into focused, production-ready software for small businesses.