简体   繁体   中英

I am getting Notice: Undefined index: joinTable

I am building a new feature onto a Symfony 2.8 application using a few Sonata bundles.

My Page.orm.xml file contains the following:

    <one-to-many target-entity="AppBundle\Entity\Synonym" field="equivalents" mapped-by="page">
        <cascade>
            <cascade-all/>
        </cascade>
    </one-to-many>

... and my Synonym.php entity definition contains the following:

/**
 * @var \Application\Sonata\PageBundle\Entity\Page
 * @ORM\ManyToOne(targetEntity="Application\Sonata\PageBundle\Entity\Page", inversedBy="equivalents", cascade={"persist"})
 */
private $page;

... and my PageAdmin.php file contains the following:

            ->add('equivalents', 'sonata_type_collection', array(
                'label' => "Equivalents",
                'cascade_validation' => true,
                'required' => false,
            ), array(
                'edit' => 'inline',
                'inline' => 'table',
                'targetEntity' => 'AppBundle\Entity\Synonym',
                'admin_code' => 'app.admin.synonym',
            ))

... and when I try to load a page admin screen, I get this error:

Notice: Undefined index: joinTable

So my question is: What do I need to add in order to make Symfony happy with this relationship?

Edit #1: Don't ask why I'm using "equivalents" rather than "synonyms." It's a long and strange story that's not worth getting into here.

Edit #2: For what it's worth, I would argue that this is not a duplicate question, since I am looking for a way to develop within the context of an existing vendor library. For example, "edit the core Doctrine functionality to avoid this index" would solve the linked problem, but it would not solve my problem, since I need to work within the constraints of an existing system.

There you have it... ;)

You should define @ORM\\JoinTable

/**
 * @var \Application\Sonata\PageBundle\Entity\Page
 * @ORM\ManyToOne(targetEntity="Application\Sonata\PageBundle\Entity\Page", inversedBy="equivalents", cascade={"persist"})
 * @ORM\JoinTable(name="page_id", referencedColumnName="id")
 */
private $page;

Do you still have your error?

The comment above from Preciel contained the fix for my situation.

If they post it as an answer, I will be happy to accept that answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM