Let's say theres a Teacher object and that Teachers holds a list of Courses objects. The courses for the Teacher can change. Some get added, some get deleted. What's the best approach to update this changes in the database. 1. Right after every change, update the database. e.g.: A course get added, immediately add that into the database as well . 2. After all changes are made to the entity/object Teacher (courses are added, courses are deleted), only then update the database with all the changes. 3. Others ??
I can see for both 1 and 2 advantages and disadvantages. For 1: I don't know how good it is when data models have direct access to the database. For 2: The algorithm its more complex because you have to compare the information in the data models with information in the database all at once.
Thank you