In Symfony2, I have these columns in a user entity:
*
* @ORM\OneToOne(targetEntity="User", inversedBy="lovername")
* @ORM\JoinColumn(name="lover", referencedColumnName="id", onDelete = "SET NULL")
*/
private $lover;
/**
* @ORM\OneToOne(targetEntity="User", mappedBy="lover", cascade={"persist"}, fetch="EXTRA_LAZY")
**/
private $lovername;
The project is a dating website, where a user can send messages only to one user, which he/she chose. The column lover
contains the id of user he/she chose to talk to.
It works properly, but it generates an additional SQL query. First Symfony downloads the row about the logged user and then every information about user which 'love' him, even if that information is useless. I need it only when user sends messages.
It is some way to write it/build database better? How do I control auto-generating queries in Symfony2?