error when executing UpdateDatabase with an association that the field has the same name as the primary key

error when executing UpdateDatabase with an association that the field has the same name as the primary key. Below are the classes and the generated sql to create the table. this situation is a failure for not checking if the field already exists? how would you ask to resolve this situation?

[Entity]
[Table('mat_movimento')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
[Sequence('seq_mat_movimento')]

TMovimentoMat = class(TModeloBsc)
private
[Column('id', [TColumnProp.Required])]
FId: int64;

[Column('sta', [TColumnProp.Required])]
FSta: integer;

[Association([TAssociationProp.Lazy])]
[ForeignKey('fk_mat_movimento_11')]
[JoinColumn('id')]
FMovimentoConsigMat: Proxy<TMovimentoConsigMat>;

function GetMovimentoConsigMat: TMovimentoConsigMat;
procedure SetMovimentoConsigMat(const Value: TMovimentoConsigMat);	

public
property Id: int64 read FId write FId;
property Sta: integer read FSta write FSta;
property MovimentoConsigMat: TMovimentoConsigMat read GetMovimentoConsigMat write SetMovimentoConsigMat;
end

[Entity]
[Table('mat_movimento_consig')]
[Id('FId', TIdGenerator.None)]

TMovimentoConsigMat = class(TModeloBsc)
private
[Column('id', [TColumnProp.Required])]
FId: int64;

[Association([TAssociationProp.Lazy, TAssociationProp.Required])]
[ForeignKey('fk_mat_movimento_consig_2')]
[JoinColumn('fat_situacao_consig_id', [TColumnProp.Required])]
FSituacaoConsigFat: Proxy<TSituacaoConsigFat>;

function GetSituacaoConsigFat: TSituacaoConsigFat;
procedure SetSituacaoConsigFat(const Value: TSituacaoConsigFat);	

public
property Id: int64 read FId write FId;
property SituacaoConsigFat: TSituacaoConsigFat read GetSituacaoConsigFat write SetSituacaoConsigFat;
end

CREATE TABLE mat_movimento (
id NUMERIC(18) NOT NULL,
sta INTEGER NOT NULL,
id NUMERIC(18),
CONSTRAINT PK_mat_movimento PRIMARY KEY (id));

You can't have two different mappings with the same column name. That will be a duplicate, indeed. You can simply set your association field as the primary key, and remove the other one. But then, of course, it can't be identity or sequence.

[Entity]
[Table('mat_movimento')]
[Id('FMovimentoConsigMat', TIdGenerator.None)]
[Sequence('seq_mat_movimento')]

I did what you suggested and the table creation worked, the post also worked, but the patch gave the following error: Could not convert variant of type (Array Variant) into type (Boolean). debugging I saw that the type that is assuming in the parameter of the primary key.
in this method TXDataAureliusModel.KeyPredicateToId is understand as composite predicate.

testing with an entity that the primary key is a primitive type

Can you please provide the exact current mapping you are using for both entities, and the exact request you are trying to execute?

Jetro.mat.MovimentoConsigMdl.pas (5.0 KB)
Jetro.mat.MovimentoMdl.pas (29.0 KB)

using patch
http://192.168.1.131:30071/jetro/MovimentoConsigMat(228)
{
"ClienteCom@xdata.ref": "ClienteCom(14)",
"VendedorAdm@xdata.ref": "ColaboradorAdm(14)",
"GerenteAdm@xdata.ref": "ColaboradorAdm(9)"
}

I can't see anything wrong at first sight.
Can you please provide a separate sample project that reproduces the issue? You could do that using SQLite as the database, that would make it easy to build a separate project. We can then debug and check what's going on at our side.

TesteComposite.zip (57.2 KB)
the post works
Post
http://localhost:2001/tms/xdata/Appointment
{
"Patient": {
"Id": 20,
"LastName": "LastName 20",
"FirstName": "FirstName 20"
},
"AppointmentDate": "2021-05-30"
}

Patch
http://localhost:2001/tms/xdata/Appointment(20)
{
"Patient": {
"Id": 20,
"LastName": "LastName alteracao",
"FirstName": "FirstName alteracao"
},
"AppointmentDate": "2021-06-01"
}

error:
{
"error": {
"code": "VariantTypeCastError",
"message": "Could not convert variant of type (Array Variant) into type (Boolean)"
}
}

Thank you very much. We were able to reproduce the problem and we have fixed it. Next release will include the fix.

our system is already in production, is there no way to release just the fix for us? how long to release a version?

We have send you updated files in private.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.