Nico
Nico

Reputation: 1251

How can i load an entity from another bundle in an entity?

Let's say i have 2 entities. Card and User. User it's in UserBundle and Card is in PublicBundle.

In user i have this function:

#namespace Kanban\UserBundle\Entity;
    /**
     * Add assignment
     *
     * @param \Kanban\PublicBundle\Entity\Card $assignment
     * @return User
     */
    public function addAssignment(\Kanban\PublicBundle\Entity\Card $assignment)
    {
        $this->assignment[] = $assignment;

        return $this;
    }

Every time i execute this command:

php app/console doctrine:schema:update --dump-sql

It throws this error:

    [Doctrine\ORM\Mapping\MappingException]                                                                    
  The target-entity Kanban\UserBundle\Entity\Card cannot be found in 'Kanban\UserBundle\Entity\User#assignm  
  ent'. 

I've tried the statement:

use Kanban\PublicBundle\Entity;
use Kanban\PublicBundle\Entity\Card;

At the beginning of the file but shows the same error. Any ideas on what i'm doing wrong?

Upvotes: 0

Views: 486

Answers (1)

Nico
Nico

Reputation: 1251

NM!,

Was a problem with the orm.yml file, changed:

manyToMany:
    assignment:
        targetEntity: Card
        cascade: {  }
        mappedBy: customer
        inversedBy: null
        joinTable: null
        orderBy: null

into

manyToMany:
    assignment:
        targetEntity: Kanban\PublicBundle\Entity\Card
        cascade: {  }
        mappedBy: customer
        inversedBy: null
        joinTable: null
        orderBy: null

And that solved the problem!

Upvotes: 1

Related Questions