Item Duplication for manually entered primary keys (#14947)

* disable save as copy for manually entered primary keys

* only mark primaryKey as readonly for generated pk's

* re-enable save-as-copy for manual ids
This commit is contained in:
Brainslug
2022-09-12 23:23:54 +02:00
committed by GitHub
parent 212481ff07
commit e72ae3b2a7
2 changed files with 4 additions and 4 deletions

View File

@@ -286,8 +286,8 @@ function useForm() {
function setPrimaryKeyReadonly(field: Field) {
if (
field.schema?.has_auto_increment === true ||
(field.schema?.is_primary_key === true && props.primaryKey !== '+')
field.schema?.is_generated === true &&
(field.schema?.has_auto_increment === true || (field.schema?.is_primary_key === true && props.primaryKey !== '+'))
) {
const fieldClone = cloneDeep(field) as any;
if (!fieldClone.meta) fieldClone.meta = {};

View File

@@ -168,8 +168,8 @@ export function useItem(collection: Ref<string>, primaryKey: Ref<string | number
...edits.value,
};
// Make sure to delete the primary key
if (primaryKeyField.value && primaryKeyField.value.field in newItem) {
// Make sure to delete the primary key if it's generated
if (primaryKeyField.value && primaryKeyField.value.schema?.is_generated && primaryKeyField.value.field in newItem) {
delete newItem[primaryKeyField.value.field];
}