User Information on entities symfony
<p>I started using symfony not long ago and at the moment I'm struggling with this problem: </p>

<p>I decided to have "who" information at entity level so I have defined these additional 4 prameters for every entity:</p>

<pre><code>/**
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
 * @ORM\JoinColumn(name="created_by", referencedColumnName="id")
 */
private $createdBy;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="created_at", type="datetime")
 */
private $createdAt;

/**
 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
 * @ORM\JoinColumn(name="updated_by", referencedColumnName="id")
 */
private $updatedBy;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="updated_at", type="datetime", nullable=true)
 */
private $updatedAt;
</code></pre>

<p>My problem is now where and how I should populate createdBy and updatedBy. ATM I do that in my controller before persisting to the database. Thou I encountered a problem when a entity is a property of another entity and lets say I have an entity called Post that has a property images of type Document the entities Post and Document both have "who" information on them and images property inside Post is defined as follows:</p>

<pre><code>/**
 * @var array
 *  
 * @ORM\ManyToMany(targetEntity="Nisand\DocumentsBundle\Entity\Document", cascade={"persist"})
 * @ORM\JoinTable(name="blog_documents",
 *      joinColumns={@ORM\JoinColumn(name="post_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")}
 *      )
 */
private $images;
</code></pre>

<p>For Post suppose I set createdBy in the controller before persisting but on Document how should that work cause that will be persisted by the cascade rule?</p>

<p>How do you guys handle in your applications the "who" columns?</p>