Answer the question
In order to leave comments, you need to log in
What is the best way to implement data validation in an entity class?
The module that exports online store orders uploads order and customer data.
The order and the buyer are different entities.
When exporting an order, it may be that the buyer is no longer in the system (for example, deleted),
and such an order does not need to be unloaded.
Each order contains a customer ID.
I implemented the Buyer entity like this:
class Buyer {
public function __construct(int $buyerId ) { ... }
public function getFullName(): string { ... }
//...
}
$orders = new OrderList();
foreach ($orders as $orderItem) {
// тут перебираю заказы, и нужно понять,
// если пользователя есть, тогда выполняет скрипт дальше
// один из вариантов через доп. метод покупателя проверять существование,
// второй - отлавливать исключения
}
Answer the question
In order to leave comments, you need to log in
It is necessary to form a method at the OrderList class level that implements a selection with a join for 2 tables, respectively, if the query is correctly formed, then only orders with existing users will be in the results.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question