Hello,
This is a question about best practices in reference to the initialization of datasources in a form. In my case, I have made a form consisting of 3 datasources:
- datasource_1
- datasource_2
- datasource_3
The datasource_2 and datasource_3 have datasource_1 as Join Source. After making several tests, I have seen that in the run() of the form, after the super(), the form only has initialized the datasource_1. When datasource_2 and 3 have Link Type: delayed, their record is loaded in its active() method. On the other hand, if the Link Type is active, their record is loaded in the active() of datasource_1.
So far so good, now let's say that datasource_3 has no record related to datasource_1, i.e. datasource_3 is blank. In this case, I want to initialize this record with information from datasource_2.
There are several ways to solve the problem. For example, check in the active() or executeQuery() if there is a datasource_3 record, and initialize otherwise. Or even use initValue() and initialize the fields directly from the datasource_2 table (using find method), instead of datasource_2 (because datasource_2 is not loaded yet).
However, I am not sure which solution is considered best practice. In my opinion, the initValue() is the cleanest. I have seen in other forms that the active() is used a lot, but I think it leads to unnecessary overhead, since the active() is called quite often.
What do you think?
Thanks in advance,
Eisenberk.