RydelHouse
RydelHouse

Reputation: 362

ManyToMany with same tables in entity - Symfony, Doctrine

I have two ManyToMany relations in one entity.

First:

 /**
 * @ORM\ManyToMany(targetEntity="RFQItem")
 * @ORM\JoinTable(name="rfqitem_to_rfq",
 *      joinColumns={@ORM\JoinColumn(name="rfqitem", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="id", referencedColumnName="id")}
 * )
 */
protected $rfqitems;

Second:

 /**
 * @ORM\ManyToMany(targetEntity="RFQItem", cascade={"persist"})
 * @ORM\JoinTable(name="new_rfqitem_to_rfq",
 *      joinColumns={@ORM\JoinColumn(name="rfqitem", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="id", referencedColumnName="id")}
 * )
 */
protected $rfq_item;

Problem is that I can't generate my entities and update schema, because generating entities gives me dublicated methods:

/**
 * Add rfq_item
 *
 * @param \RFQ\IronilBundle\Entity\RFQItem $rfqItem
 * @return RFQ
 */
public function addRfqItem(\RFQ\IronilBundle\Entity\RFQItem $rfqItem)
{
    $this->rfq_item[] = $rfqItem;

    return $this;
}

which throws an error:

Fatal error: Cannot redeclare RFQ\IronilBundle\Entity\RFQ::addRfqitem()

I need these two relations in one entity, because one is for adding previously made RFQitems, but second is to create new RFQitems and this all is in one form. What I can do resolve this?

Upvotes: 2

Views: 1130

Answers (1)

Michael Sivolobov
Michael Sivolobov

Reputation: 13265

Doctrine generate methods with names based on your fields. Your fields are very similar: Doctrine will omit ending "s" and underscores, convert strings to lowercase. Your fields will look like $rfqitem and $rfqitem. As you can see Doctrine will see your fields with two absolutely equal names. You need to rename one of your fields $rfqitems, $rfq_item.

Try something more semantic like: $oldRFQItems and $newRFQItems.

Upvotes: 2

Related Questions