add_visible_foreign_key
Add an inbound foreign key to the visible-foreign-keys list for a context, so related tables display on record views. Changes are staged until apply_annotations() is called.
Instructions
Add a foreign key to the visible-foreign-keys list for a specific context.
This is a convenience tool for adding related tables without replacing the entire visible-foreign-keys annotation. Changes are staged until apply_annotations() is called.
Args: table_name: Name of the table. context: The context to modify (typically "detailed" or "*"). foreign_key: Foreign key to add. Can be: - List: inbound foreign key reference (e.g., ["schema", "Other_Table_fkey"]) - Dict: pseudo-column definition for complex relationships position: Position to insert at (0-indexed). If None, appends to end.
Contexts for visible-foreign-keys:
Context | Description | When Used |
| Default for all contexts | Fallback when specific context not set |
| Full record view | Related tables shown on single record page |
Important: Only INBOUND foreign keys are valid - these are foreign keys from OTHER tables that reference THIS table. Use list_foreign_keys() to see which inbound foreign keys are available.
Returns: JSON with the updated foreign key list for the context.
Examples: # Add inbound foreign key to detailed view add_visible_foreign_key("Subject", "detailed", ["domain", "Image_Subject_fkey"])
# Add at specific position
add_visible_foreign_key("Subject", "detailed", ["domain", "Diagnosis_Subject_fkey"], 0)
# Add pseudo-column for complex relationship
add_visible_foreign_key("Subject", "detailed", {
"source": [{"inbound": ["domain", "Image_Subject_fkey"]}],
"markdown_name": "Subject Images"
})
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | Yes | ||
| position | No | ||
| table_name | Yes | ||
| foreign_key | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |