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.
You mention repositories. Do you use an ORM system like Doctrine or do you use Laminas’ own DBAL system?
I dont use ORM. I use Laminas own DBAL system
Step1: You Can create 4 different repositories:
- Table named as a_products_category,
Step2:Create service which copy data from tables to archive
Step3: check in controller for product status and call service method
I’ll do that.
Anyway i think pass table name(prefix) as param is a bad way.
Hi @ kliker02
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:
public function fetchActiveProducts(): ProductCollection;
public function fetchInactiveProducts(): ProductCollection;
This makes it uninteresting for the rest of the application where and how something is stored.
Thank you for your help. I will do according to your instructions ( froschdesign and kliker02).