Doctrine2 OneToMany without mappedBy

I have a listing of an object with OneToMany to represent the entity, the key between them is view.content_id, which contains the listing identifier, however it also applies to other objects, so adding

/**
 * @var Listing
 *
 * @ORM\ManyToOne(targetEntity="\Acme\Bundle\Entity\Listing", inversedBy="views")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="content_id", referencedColumnName="id")
 * })
 */
private $listing;

It slows down by sight, because when you save the view object, the content_id becomes zero.

How can i fix this?

Relationship to listing:

/**
 * @var views
 *
 * @ORM\OneToMany(targetEntity="\Acme\Bundle\Entity\View", mappedBy="listing")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="id", referencedColumnName="content_id")
 * })
 */
private $views;

I make queries by joining the Listing.views list and adding WITH content_type =: ContentType, which distinguishes some of the results of the β€œview”.

+5
source share
1 answer

I'm late to the party, but I think I will answer if this helps someone else.

- , , , FK. :

$listing = $em->getRepository('Acme\Bundle\Entity\Listing')
              ->find($content_id);
$view->setListing($listing);

:

$view->setListing($content_id);

, - , .

: ^)

0

All Articles