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:


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:

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


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.


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.