#1 2024-02-15 08:17:20

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

is it possible to delete a zero ID through ORM?

I have noticed that the following works:
if MemberExists(TOrmsometing,0) then ....
but the following does not:
Delete(TOrmsometing,0)

Is it possible in mormot.orm.sql line 1317 to allow zero IDs to be deleted through orm?

function TRestStorageExternal.EngineDelete(TableModelIndex: integer;
  ID: TID): boolean;
begin
  if (ID <= 0) or
     (TableModelIndex < 0) or
     (Model.Tables[TableModelIndex] <> fStoredClass) then
    result := false

Thank you in advance

Offline

#2 2024-02-15 11:27:23

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: is it possible to delete a zero ID through ORM?

zero is invalid, a valid ID value is >=1.

Last edited by pvn0 (2024-02-15 11:27:41)

Offline

#3 2024-02-15 12:00:08

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: is it possible to delete a zero ID through ORM?

I just post it because MemberExists(TOrmsometing,0), a ORM method, accept it and it works
I tried also to run the tests without errors after changing TRestStorageExternal.EngineDelete to be like the following :

function TRestStorageExternal.EngineDelete(TableModelIndex: integer;
  ID: TID): boolean;
begin
  if (ID < 0) or
     (TableModelIndex < 0) or
     (Model.Tables[TableModelIndex] <> fStoredClass) then
    result := false

I know that ID:0 has a meaning for Add/AddOrUpdate in Delete as in MemberExists I am not sure.
I am not sure also about using Delete in batches

Offline

#4 2024-02-20 08:07:06

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: is it possible to delete a zero ID through ORM?

@ab do you consider the above change as acceptable for the Delete as it works for MembereExists?

Thank you in advance

Offline

#5 2024-02-20 11:26:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,205
Website

Re: is it possible to delete a zero ID through ORM?

The value 0 has a meaning of invalid ID everywhere in the framework by convention.

Perhaps it is not properly checked everywhere but it is what is expected.

So I don't consider allowing to delete an ID = 0 when we can't Add or Update such ID. wink

Offline

#6 2024-02-20 12:27:06

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: is it possible to delete a zero ID through ORM?

No problem. I did in an other way. Thank you

Offline

Board footer

Powered by FluxBB