XDATA - AURELIUS - DATA MODELER missing field in entities used for foreign keys. (old post)

Hi,
from my old post.
How do I manage the fields in entities used for foreign keys? I need them to serialize/deserialize and read the values ​​for calculations, but those fields don't appear in the generated entities.
In their place there is the detail or related class, but there is no the true field with its value.
Thanks

XDATA - AURELIUS - DATA MODELER missing field in entities used for foreign keys.

Can you please better elaborate your question so we can fully understand what is the issue?

Please provide steps to reproduce the issue.

Well,

OK, let's take an example.
If I have this table in the database, which also has CountryID among its fields, related to the Country table. The generated entity has the below structure:
But where did CountryID go? If I need to use it for other purposes, display it, or reassign it for other purposes, where do I find it? If I need to serialize the entity's properties, I don't have that value, but the related class (Country). Why is it missing from the entity, if I actually need it for other uses o scopes, , besides the relationship with the Country entity?

I hope I was clear with my poor English :-)

Entity,Automapping
TCustomer = class
strict private
FId: integer;
FName: string;
FTitle: string;
FBirthday: TDateTime;
FCountry: TCountry;
public
property Id: Integer read FId write FId;
property Name: string read FName write FName;
property Title: string read FTitle write FTitle;
property Birthday: TDateTime read FDateTime write FDateTime;
property Country: TCountry read FCountry write FCountry;
end;

Country id is available through property Country and then its property Id:

CountryId := Customer.Country.Id;

Okay, I agree.
But if I need to perform serialization, deserialization, consistency checks, or value equality checks AUTOMATICALLY, I don't have all the values ​​in the database that correspond to the entity's "linear" values, excluding related classes.
So I'm missing all the fields that are relationship keys.
Clearly, my exception concerns direct operations on entities for "parallel" management to that performed by Aurelius itself.
Question: if I manually implement these original fields in the classes (for now), will we encounter any problems? Are they normally set or managed from Aurelius?
Thanks

If you mean mapping CountryID database column to Integer field instead of TCountry, it's possible. But you will lose the Aurelius mechanism of doing joins and retrieving all the associated columns from Country table (and any other foreign key table).

You can also declare all associations are Proxy<T> and which that you have direct access to the foreign key values using Proxy.Key, as explained here: How Load, Proxy<T>.Key

Hi Wagner,

If you mean mapping CountryID database column to Integer field >instead of TCountry, it's possible. But you will lose the Aurelius >mechanism of doing joins and retrieving all the associated columns >from Country table (and any other foreign key table).

NO, I intend to have BOTH CountryID (Integer) AND TCountry, because I need to "read" all real fields connected with DB table fields.
What do you think?

Use the mentioned Proxy<T> approach.

OK, but when deserializing from external JSON (via a service), how can I automatically deserialize this entity (another example)?
{"name": "Mario", "surname": "Rossi", "age": 30, "CountryID": 23}
How can I deserialize a simple JSON into an entity without manually managing the "key" on a case-by-case basis?
In our Xdata services, we automatically deserialize dozens of different entities through a single function that doesn't have a defined entity but deserializes into entities by specifying the class, therefore without any fixed definition. What happens to that CountryID field?
I don't think it's right that it's not "visible" in the entity, for a thousand different reasons and needs.
It may seem like a minor problem, but it affects the entire project by forcing us NOT to use related tables, which is clearly NOT acceptable..

If you have an association id (CountryID) and you want to associate that country to a customer, you have to retrieve the associated object.

You must do something like this:

Customer.Country := Manager.Find<TCountry>(JsonObject['CountryId'].AsInteger)

How can I do this in a function that automatically deserializes any entity of the class type present in the model? I emphasize, automatically.
At this point, if I manually declare that property, in addition to the "proxy" class, are there any problems?

Sorry but I don't get wha you mean. TXDataClient deserializes "any entity of the class type present in the model" (if I understand what you mean).

But the "class present in the model" does not have a CountryID integer. It has an associaton, a Country: TCountry. That's how Aurelius maps associations.