Answer the question
In order to leave comments, you need to log in
Some questions about DoctrineORM and Symfony?
During the study of the symphony, several questions arose that I could not figure out. I want to get help from hardened colleagues.
1) In the documentation, it is advised to prescribe getters / seters for all entity fields. I don't understand why, if php has __call() . The situation when you need to do individual processing of the field is clear, but why in most cases clog the class with the same type of methods - I don’t understand. What's the point?
2) I made a foreign key from the address to the user, indicated the actions in a cascade, the connection is displayed in the PMA, but the parent element does not want to be deleted. there are children. What is the problem?
/**
* @ORM\ManyToOne(targetEntity="Customer", cascade={"remove"}, fetch="EAGER")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="customer_id")
*/
protected $customerId;
/**
* @ORM\Column(type="datetime", name="inserted_at", options={"default" : "CURRENT_TIMESTAMP"})
*/
Answer the question
In order to leave comments, you need to log in
1) the doctrine creates proxy objects for all your entities, and in the future you will receive them from the database. in proxy objects for getters and setters, it makes wrapper methods.
+ It's very inconvenient to work with call, because there is no auto-completion in the development environment, only because of this I would not use the call.
2) perhaps the cache was not reset, the doctrine sometimes caches annotations and does not apply them immediately with a small change.
3) humble yourself. there is an overhead, of course, he was indignant at the beginning, but the OOP requires sacrifice.
4) yes, just add it to the constructor, there are no problems, the advantage is that this field is immediately available, as well as a mega bonus for writing tests when you need to create objects with the specified dates.
I don't understand why, if php has __call().
How to make an ORM annotation so that a field of type "datetime" is filled with the current date-time?
class Имя_Класса
{
$поле_времяни;
/**
* Set поле_времяни
*
* @param \DateTime
*
* @return Имя_Класса
*/
public function поле_времяни()
{
$this->поле_времяни = new \DateTime('today');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question