1

Anybody knows how to accomplish a OneToMany relation within 2 projects (let's say cross-database wise, both have their own project structure, namespaces and database).

Let's say I have one Entity in Project A:

Movie.php (Entity Project A)

class Movie {

    // ... some other properties

    /**
     * @ORM\OneToMany(targetEntity="Moviechild/Project B", mappedBy="movie")
     */
    protected $moviechilds;

    // ...

and another Entity in Project B:

Moviechild.php (Entity Project B)

class Moviechild {

    // ...

    /**
     * @ORM\ManyToOne(targetEntity="Movie/Project A", inversedBy="moviechilds")
     * @ORM\JoinColumn(name="movie_id", referencedColumnName="id")
     */
    protected $movie;

    // ...
Florent
  • 12,310
  • 10
  • 49
  • 58
Mike
  • 2,686
  • 7
  • 44
  • 61

1 Answers1

2

You have to instantiate ProjectBBundle inside Project A's AppKernel and vice versa.

Then use correct namespaces inside targetEntity property annotation:

Movie.php (Entity Project A)

namespace ProjectABundle\Entity;

class Movie {
    /**
     * @ORM\OneToMany(targetEntity="ProjectBBundle\Entity\Moviechild", mappedBy="movie")
     */
    protected $moviechilds;

    // ...

Moviechild.php (Entity Project B)

namespace ProjectBBundle\Entity;

class Moviechild {
    /**
     * @ORM\ManyToOne(targetEntity="ProjectABundle\Entity\Movie", inversedBy="moviechilds")
     * @ORM\JoinColumn(name="movie_id", referencedColumnName="id")
     */
    protected $movie;

    // ...
Florent
  • 12,310
  • 10
  • 49
  • 58
  • Yes thanks Florent, actually I had to do it differently, because the project was changing. But thanks for your answer, I appreciate it very much! Best – Mike Sep 12 '12 at 12:38