Answer the question
In order to leave comments, you need to log in
Is it right to create an instance of a class from a method of this class?
For example, I need to add 100 records to a table. In the controller, I make an instance of class A and call its method, this method will create 100 instances of this class, in a loop. Is that the right thing to do?
Answer the question
In order to leave comments, you need to log in
Something similar to the factory pattern.
But in general, queries to the database in a loop are not the best practice.
It is better to form SQL in a cycle and already with 1 query and insert all 100 at once into a transaction
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question