mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
TMVCActiveRecord // in WriteableFieldsCount is considered also a not-autogenerated primary key
This commit is contained in:
parent
2e706f483f
commit
1bb4d7f7ca
@ -278,6 +278,7 @@ type
|
||||
fDefaultRQLFilter: string;
|
||||
fMap: TFieldsMap;
|
||||
fPrimaryKey: TRTTIField;
|
||||
fPrimaryKeyInInsert: Boolean;
|
||||
fMapping: TMVCFieldsMapping;
|
||||
fPropsAttributes: TArray<TCustomAttribute>;
|
||||
fProps: TArray<TRTTIField>;
|
||||
@ -1590,6 +1591,7 @@ begin
|
||||
begin
|
||||
if foPrimaryKey in MVCTableFieldAttribute(lAttribute).FieldOptions then
|
||||
begin
|
||||
lTableMap.fPrimaryKeyInInsert := not (foAutoGenerated in MVCTableFieldAttribute(lAttribute).FieldOptions);
|
||||
lTableMap.fPrimaryKey := lRTTIField;
|
||||
lPrimaryFieldTypeAsStr := lTableMap.fPrimaryKey.FieldType.ToString.ToLowerInvariant;
|
||||
if lPrimaryFieldTypeAsStr.EndsWith('int64') then
|
||||
@ -1678,13 +1680,13 @@ begin
|
||||
OnValidation(TMVCEntityAction.eaCreate);
|
||||
OnBeforeInsert;
|
||||
OnBeforeInsertOrUpdate;
|
||||
if fTableMap.fMap.WritableFieldsCount = 0 then
|
||||
if (fTableMap.fMap.WritableFieldsCount = 0) and (not fTableMap.fPrimaryKeyInInsert) then
|
||||
begin
|
||||
raise EMVCActiveRecord.CreateFmt
|
||||
('Cannot insert an entity if no fields are writable. Class [%s] mapped on table [%s]',
|
||||
[ClassName, TableName]);
|
||||
end;
|
||||
if (foAutoGenerated in fTableMap.fPrimaryKeyOptions) then
|
||||
if (not fTableMap.fPrimaryKeyInInsert) {autogenerated} then
|
||||
begin
|
||||
if not SQLGenerator.HasReturning then
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user