“How can I know the dataClass of an entity? I need it to write generic methods“. “I need information about a field in a dataClass: what is its type? Is it indexed? Is it unique?“. These are the kinds of questions we’ve heard you asking on the forum. 4D v17 R5 provides the answers: introducing new ORDA member methods to provide useful information about your database. Keep reading, because you’ll appreciate the benefits of reducing the size of your code and making it reusable and easy to maintain!
Now, you can get structure-related information such as table or field number. This can be helpful when integrating ORDA step-by-step into your classic 4D code. However, the main purpose of these member methods is to give you a way to write generic code that’s applicable no matter the database’s structure.
Get the dataClass of an entity or an entity selection
What a joy to have a clever entity that knows its own dataClass!
The getDataClass() member method returns the dataClass object corresponding to the entity. Then, you can call any member method available on the dataClass.
In the example below, we call the new() member method. It creates a new entity from the one provided and copies the address data. An object containing the property name and its value for the newly created entity is also received.
//We copy address from the received entity
//We fill the created entity with received property name and value
entity selection dataclass
The getDataClass() member method returns the dataClass object corresponding to the entity selection. The method below receives an entity selection and creates new entities with the same address data.
alert(String($inputSelection.length) + " entities are going to be duplicated")
alert(String($newEntitySelection.length) + " entities have been created")
get information about a dataclass
The getInfo() member method available on the dataClass, also returns useful information. In the example below, we get IDs matching the primary key of the Persons dataClass, then we retrieve the corresponding entities.
$settings.parameters:=New object("receivedIds";getIds ())
// The getIds() method returns a collection of IDs
$es:=ds.Persons.query(":pk in :receivedIds";$settings)
With 4D V17.0, you learned that each dataClass attribute is an object. They’ve now been enhanced with conceptual and structural information.
Here’s a quick example.
Download the HDI above to learn more! And be sure to check out the doc center.