Flattening attributes is just another way to conceptually add an attribute from one entity to another. A generally better approach is to traverse the object graph directly through relationships. Enterprise Objects makes this easy by supporting the notion of key paths.
The difference between flattening attributes and traversing the object graph (either programmatically or by using key paths) is that the values of flattened attributes are tied to the database rather than the object graph. If an enterprise object in the object graph changes, a flattened attribute can quickly get out of sync.
For example, suppose you flatten a departmentName
attribute
into an Employee object. If a user then changes an employees
department reference to a different department or changes the name
of the department itself, the flattened attribute wont reflect
the change until the changes in the object graph are committed to
the database and the data is refetched (this is because flattened
attributes are derived attributessee Definition (Derived Attributes) for
more details). However, if youre using key paths in this scenario,
users see changes to data as soon as they happen in the object graph.
This ensures that your applications view of the data remains
internally consistent.
Therefore, you should use flattened attributes only in the following cases: