Answer the question
In order to leave comments, you need to log in
How to solve the problem of building several types of entities with the possibility of incomplete filling of an entity from one database table?
There is a table in the database.
Each table row can be a specific entity, for example: "news, article, novelty", etc.
They have both the same parameters and different ones, for example: a title and a link, everyone has it, only a novelty has a rating.
To implement the getters of these parameters, I created an abstract class, and defined a constructor in it:
abstract class Base
{
protected $data;
private $categoryIds;
public function __construct(array $params)
{
$this->data = new NullObject($params);
}
public function getTitle() :string
{
return $this->data->title;
}
//...
}
Answer the question
In order to leave comments, you need to log in
What you are doing, there is such an implementation in Doctrine . You can see how it is implemented there.
Without describing the parameters themselves, it is difficult to understand the difference between the entities, in general, the correctness of your decision and give more or less adequate comments. The only thing I can assume, based on your description, is that you did not correctly build the inheritance hierarchy. If it were correct, such questions would not arise. Therefore, you should reconsider and rethink it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question