Skip to content

Commit 388bf32

Browse files
authored
Merge pull request #1735 from rocket-admin/backend_identity_field_prompt
refactor: update widget selection rules to exclude foreign key columns
2 parents 36d3ad8 + eca7bbd commit 388bf32

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

backend/src/entities/ai/ai.service.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,11 @@ TIMEZONE WIDGET:
216216
- Use for: timezone, tz columns
217217
- Params: {"allow_null": false}
218218
219-
FOREIGN_KEY WIDGET:
220-
- Use ONLY for columns that reference another table but are NOT detected as foreign keys
221-
- Skip if foreign key is already detected in table structure
222-
- Params: {"column_name": "user_id", "referenced_table_name": "users", "referenced_column_name": "id"}
223-
224219
WIDGET SELECTION RULES:
225220
1. Match widget type to column data type AND column name semantics
226-
2. For password/hash columns: Always use Password with encrypt:true and detect algorithm from hash pattern
227-
3. For status/type/category columns: Use Select with sensible options inferred from column name
228-
4. For columns ending in _id that aren't foreign keys: Consider Foreign_key widget
221+
2. DO NOT generate widgets for columns that are foreign keys (listed in the Foreign Keys section) - they are handled automatically by the system
222+
3. For password/hash columns: Always use Password with encrypt:true and detect algorithm from hash pattern
223+
4. For status/type/category columns: Use Select with sensible options inferred from column name
229224
5. For columns named email, phone, url, etc.: Use specialized widgets (String with isEmail validator, Phone, URL)
230225
6. For auto_increment or primary key columns: Use Readonly
231226
7. Provide widget_params only when the widget type benefits from configuration
@@ -303,6 +298,7 @@ IMPORTANT:
303298
return aiResponse.tables.map((tableSettings) => {
304299
const tableInfo = tablesInformation.find((t) => t.table_name === tableSettings.table_name);
305300
const validColumnNames = tableInfo?.structure.map((col) => col.column_name) || [];
301+
const foreignKeyColumns = new Set(tableInfo?.foreignKeys.map((fk) => fk.column_name) || []);
306302

307303
const requiredFieldsWithoutDefault = new Set(
308304
tableInfo?.structure
@@ -336,7 +332,7 @@ IMPORTANT:
336332
? tableSettings.identity_column
337333
: null;
338334
settings.table_widgets = tableSettings.widgets
339-
.filter((w) => validColumnNames.includes(w.field_name))
335+
.filter((w) => validColumnNames.includes(w.field_name) && !foreignKeyColumns.has(w.field_name))
340336
.map((widgetData) => {
341337
const widgetType = this.mapWidgetType(widgetData.widget_type);
342338
if (!widgetType || widgetType === WidgetTypeEnum.Foreign_key) {

0 commit comments

Comments
 (0)