Consider the following simple example: Assume we have a class 'Account' which contains a list of 'Transactions'. Likewise, in the database we have two tables; 'Account' and 'Transactions'.
Now, in our program, we consider the Account to be the primary object. A typical use case would involve adding new transactions to the Account. These new transactions would then have to be persisted in the database.
With respect to inserting only the new transactions in the database, what are some common patterns for identifying the transactions in the account-object that are actually new?
Obviously, one could do something like "select max(transaction_id) from transaction where account_id = 5", and then insert only the transactions in the object with id greater than max(transaction_id). However, I feel there should be solutions which do not require an additional query.
Aucun commentaire:
Enregistrer un commentaire