what is the best practice for passing the table prefix to the repository. In my project, depending on the controller, I would like to retrieve data from repository queries, but with different prefix depending on the state of the master object. Let’s say for active products (a_products table where I keep the product status) I fetch data from active related tables “a_products_category”, “a_products_info” etc, but when I change the product status to inactive the data from the tables are copied to the tables with inactive items like “a_archive_products_category”, “a_archive_products_info” etc. This solution is optimal for me in terms of database performance. The question is whether to pass the prefixes as a variable to each method called, or is there a better way.
Thank you for your suggestions. I had doubts about creating a repository copy of the tables a_… for a_archive_… (basically the same functions) is not duplicating code and functions, i.e. denying object-oriented programming, and passing a parameter with a prefix will result in no copying of methods that basically do the same thing.
If a database is used or which table is a detail that is only of interest at the persistence layer!
For example, use a repository with the following methods:
interface ProductRepositoryInterface
{
public function fetchActiveProducts(): ProductCollection;
public function fetchInactiveProducts(): ProductCollection;
}
This makes it uninteresting for the rest of the application where and how something is stored.