Wrong Generated SQL for ForeignJoinColumn


I was reviewing the help file and found that was not necessary to inform the ForeignJoinColumn field, and that instead Aurelius is going to use the ID. Since all my tables are ID based with GUI that makes easier.

I have removed then all and they all look like this now:

    [ManyValuedAssociation([TAssociationProp.Lazy], [])]
    [ForeignJoinColumn('', [])]
    FMeiosContato: Proxy<TList<TEntityMeiosContato>>;

However at first test (I am using ElevateDB) it created the following sql, that raised and erro on the database:

CREATE TABLE SYSPROFILEITEMS ('#$D#$A'  ID GUID NOT NULL,'#$D#$A'  ALLOW BOOLEAN,'#$D#$A'  RESOURCETYPE INTEGER,'#$D#$A'  RESOURCENAME VARCHAR(255),'#$D#$A'  ROW INTEGER,'#$D#$A'  COL INTEGER,'#$D#$A'   GUID,'#$D#$A'  CONSTRAINT PK_SYSPROFILEITEMS PRIMARY KEY (ID));

The problem is that GUID after the COL INTEGER, if I am not wrong. I don't have a column with that name, and have not defined any join with that name.

As soon as I have defined back again the ForeignJoinColumn name it generated correctly the sql.

That partial field created is generated based in a Join from other entities, since this particular entities does not reference any other, it is actually a pretty simple entity.

My table basic structure for the Id is this:

  [Entity]
  [Table('SYSPROFILEITEMS')]
  [Id('ID', TIdGenerator.Guid)]
  TEntitySystemProfileItems = class(TNaharEntity)
  private
    FId: TGuid;
    [Column('ID', [TColumnProp.Unique, TColumnProp.Required, TColumnProp.NoUpdate])]
    property    Id: TGuid read FId write FId;
 end;

Eduardo

You MUST provide the column name in ForeignJoinColumn attribute (only thing you can do is omit the ForeignJoinColumn attribute as a whole, if you are using [Automapping] attribute).

The column name is the name of column in the child table (the column that references the primary table). What is optional is the ReferencedColumnName parameter (the third parameter) which indicates which column in parent (primary) table is referenced by the child column. If that column is not specified, then the id column is used as referenced column.

ok, I reverted my code to the one with that informed and it is now back working again.


However in the documentation there is:

"Indicates the column name in the associated table that will be referenced as
foreign key. The referenced column must be unique in the associated table. This
parameter is optional, if it's not specified (and usually it won't), the name of
Id field will be used - in other words, the
primary key of the associated table will be referenced by the foreign key."

for the ForeignJoinColumn. Based on that I decided to remove (it says that I should not use it normally).

I believe it is not clear on the documentation.

Thanks.

The documentation says that about the >>ReferencedColumnName<< parameter, which is the third parameter in ForeignJoinColumn attribute, not the >>Name<< parameter, which is the first one. I think it's very clear.