Editing values for columns with a foreign key constraint applied #796
Replies: 6 comments 34 replies
-
Overall
Reactions
Additional challenges
Thoughts, opinions
Ideas
|
Beta Was this translation helpful? Give feedback.
-
I'm less worried about auto-complete in this case, and more concerned about repetition. Imagine you're going through your track list, and organizing them into albums. One of the advantages of a proper DB is that you don't have to type the album name over and over, so it would be cool if the UI guided the user towards using the primary key the next time they want that album. Another idea: Maybe a UI flow that lets the user choose a given row from the referenced table, and then choose multiple rows in the referencing table (e.g., by ctrl-clicking or something), and then "enter" to do it all at once. This also really solidifies the foreign key concept for them. Finally, for missing foreign records, it would be really cool, once we have the concept of record form input implemented, to use it in that case. That way, they'd avoid having to navigate away to the other table for input. They could just input the needed record right there, and keep moving. |
Beta Was this translation helpful? Give feedback.
-
@ghislaineguerin I think everyone else has covered the points I wanted to make. I just want to reiterate that I don't think we can rely on a single column either for autocomplete or for displaying the value. I think we need to find a way to show multiple values at the very least (maybe the first 3 columns?) to help with the ambiguity. I'm fine with whichever autocomplete option you'd like to go with, the main problem I think we need to solve is how to display the foreign key value without needing the user to configure something first. |
Beta Was this translation helpful? Give feedback.
-
Extending from "Option 2", which is @ghislaineguerin's choice and the "Modal selector" idea discussed here: #796 (reply in thread) I think we can combine the "search and enforcing selection from the list of records only" idea with the "modal" idea, and include searching through all columns. Rough mockup:
We can come up with better names for the terms used, this is just a rough mockup to get it out visually. |
Beta Was this translation helpful? Give feedback.
-
Is this feasible from a technical standpoint, and does it offer good performance? I assume that the user could select which fields to include in these "lookup" cards at some point. Another idea is that we initially show the cards with the first 3 fields, and there's some sort of button to configure, and other fields can be selected from there. We can explain that this will be saved when retrieving records from that particular table, similar to the "view" idea proposed by @seancolsen |
Beta Was this translation helpful? Give feedback.
-
Just like @seancolsen mentioned, I am not able to find much difference between options 1 and 2. From what I understood, the first option allows you to enter an invalid value in the input table, which would anyway throw up an error, other than that I am not able to come up with differences, I think I am missing some key details between those options. I came across some code examples with similar functionality that could be helpful to play around with As for the search, functionality is concerned I would prefer if we keep it to basic search. When a foreign key constraint is added, we could ask for the column(can be extended to a limited set of columns) to be used as a lookup field, with the first column(or the column with the most repeated value) selected as default. For anything more than a basic search, I think we should go with views as it provides the flexibility the user would need, as they would need multi-column, related column, full-text fuzzy search, ranking and if we have it by default, it would end up abstracting a lot of underlying details from the user. We could use trigrams or full-text search without index and have the user create an index if they find the query to be slow(or we could monitor and let them know), this should help them make a decision between necessity vs complexity. |
Beta Was this translation helpful? Give feedback.
-
How can we make it easy for users to add linked records?
A foreign key constraint limits the data that the user can enter for a column to the values in the referenced table. In the case of tables created within Mathesar, the values should match the ID of the referenced table record, as they are set as the primary key.
We aim to make linking records easy for users so that they don't have to create complex tables or duplicate data and so that we can instead encourage them to use views to tie together related data.
The problem
We want users to only add the primary key values to the foreign key column, as this would match the values from the database. However, not all input methods are helpful when it comes to limiting value options.
A fundamental part of making this task more efficient will be in helping the user retrieve the records from the referencing table. For this purpose, we want to provide the user with a list of records from the referenced table whenever a foreign key field is on edit mode. However, to prevent errors in entering these values, we must restrict users to only set their values to those within the list.
To restrict values, we have two choices:
In all cases:
Option 1: Allowing the user to type in the values (cell turns into input)
This first option allows the user to enter values by typing into the cell and provides an autocomplete feature. However, the user is not blocked from entering other non-listed values, which might trigger an error.
Option 2: Enforcing selection from the list of records only (my preference)
This option removes the ability to type directly into the cell and instead restricts the input methods to list selection only.
We start from a newly created column with a foreign key constraint applied to it. When empty, the cells will have a 'search' icon.
Clicking on the cell will reveal the list of records for the referenced table.
As the user starts searching, the list narrows
Option 3: Allowing the user to type in any value and only save if valid, but provide a button to display the records list menu
This option could be a hybrid between options 1 and 2 but might be more slow and tedious for users that want to start typing directly into the cell. It also fails to prevent errors as efficiently as option 2.
Additional Problems to Solve
Displaying user-friendly values instead of ID numbers
Id numbers can be long and hard to read or differentiate from others. For that reason, we might opt to show the values for the first next column after the Id. This is not the optimal solution, but it might work until we implement lookup field functionality.
Beta Was this translation helpful? Give feedback.
All reactions