Is "parent" a reserved word for naming field?

Hi there,


I made a test here, changing this:

    [Association([TAssociationProp.Lazy], [])]
    [JoinColumn('IDGRUPO', [])]
    FGrupo: Proxy<TEntityGrupo>;

public
    property GRUPO: TEntityGrupo read GetGrupo write SetGrupo;

to this:

    property Parent: TEntityGrupo read GetGrupo write SetGrupo;

remaining the field and tags the same.

When I try to import on TAureliusDataSet the version with PARENT does not show up. If I revert back to GRUPO it does show up. 

What is that?

Don't you have some persistent fields defined in your Aurelius dataset?

nope, I have no persistent fields there. 


However is something else, is not the "parent" name exclusivelly, Anything I use to change the property name from "grupo" does not work. Even if I just add an "s" to the end.

Follow the complete declaration of this class:

type
  [Entity]
  [Table('GRUPO')]
  [Id('ID', TIdGenerator.Guid)]
  TEntityGrupo = class(TNaharEntity)
  private
    FId: TGuid;
    FNome: string;
    FDescricao: Nullable<string>;
    FLink: Nullable<string>;

    [Association([TAssociationProp.Lazy], [])]
    [JoinColumn('IDGRUPO', [])]
    FGrupo: Proxy<TEntityGrupo>;

  private
    function  GetDominio: Integer;
    procedure SetDominio(const Value: Integer);
    procedure SetDescricao(const Value: Nullable<string>);
    procedure SetNome(const Value: string);
    function  GetOwner: TGUID;
    procedure SetOwner(const Value: TGUID);
    function  GetGrupo: TEntityGrupo;
    procedure SetGrupo(const Value: TEntityGrupo);
    procedure SetLink(const Value: Nullable<string>);

  public
    [Column('ID', [TColumnProp.Unique, TColumnProp.Required, TColumnProp.NoUpdate])]
    property Id: TGUID read FId write FId;

    [Column('DOMINIO', [], 0)]
    property Dominio: Integer read GetDominio write SetDominio;

    [Column('OWNER', [], 0)]
    property Owner: TGUID read GetOwner write SetOwner;

    [Column('NOME', [TColumnProp.Required], 100)]
    property Nome: string read FNome write SetNome;

    [Column('DESCRICAO', [], 100)]
    property Descricao: Nullable<string> read FDescricao write SetDescricao;

    property Grupo: TEntityGrupo read GetGrupo write SetGrupo;

    [Column('LINK', [], 20)]
    property Link: Nullable<string> read FLink write SetLink;
  end;

I am puzzled by that. 

How it looks like on TAureliusDataSet:

http://snag.gy/k5FsT.jpg


TAureliusDataset uses the existing entity mapping as the base for the class fields/properties that it considers to be data fields (TFields).

In your mapping, what is actually mapped is the field "FGrupo", not property "Grupo". Thus, it is getting "FGrupo" field and removing the "F" is front of it (this is internal and by default) and making it a "Group" property. Thus, you need to rename "FGrupo" field, not "Grupo" property (although the best practice would be renaming both of course)

I have a question regarding this TEntityGrupo that I have posted the code.


The property Grupo should bring the reference to the parent, since it is a tree hierarchy;

I have made an extension of the TreeView component to accept the DataSource and define the fields to be used for loading the tree structured and display it.

my problem is that Grupo.ID does not bring me back the Parent.ID that is a GUID

I get a EDatabaseError Field grupo.id not found.

According to the documentation I am allowed to navigate the structure using dots. I know that this particular entity has the parent. (DataSet.FieldByName(Grupo).Value <> 0 (it is the pointer of the entity defined)

What am i doing wrong?

Have you declared the field as persistent field? Fields for subproperties are not defined automatically for the dataset, you have to create persistent fields for them.

You right, it is in the manual. I misunderstood that.

It's important to note that sub-property fields are not created by default when using default fields. In the example of TCustomer class above, only field "Country" will be created by default, but not "Country.Name" or any of its sub-properties. To use a sub-property field, you must manually add the field to the dataset before opening it. Just like any other TDataset, you do that at design-time, or at runtime:

 

with TStringField.Create(Self) do

begin

  FieldName := 'Country.Name';

  Dataset := AureliusDataset1;

end;