Reputation: 43
I have a problem in a OneToMany-relationship in Symfony2. I created the entities
Mandator
// src/Pso/ProjectBundle/Entity/Mandator.php
namespace Pso\ProjectBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="mandator", options={"collate"="utf8_general_ci",
"charset"="utf8", "engine"="InnoDB"})
* @ORM\Entity()
*/
class Mandator
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="Pso\ProjectBundle\Entity\Project",
mappedBy="mandator")
*/
private $projects;
/**
* @ORM\Column(type="string", length=50, nullable=false)
*/
private $longname;
/**
* @ORM\Column(type="string", length=50, nullable=false)
*/
private $shortname;
public function __construct() {
$this->projects = new ArrayCollection();
}
}
and the entity Project, wgich has a relationship to another entity called User
// src/Pso/ProjectBundle/Entity/Project.php
namespace Pso\ProjectBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="project", options={"collate"="utf8_general_ci",
"charset"="utf8", "engine"="InnoDB"})
* @ORM\Entity(repositoryClass="Pso\ProjectBundle\Entity\ProjectRepository")
* @ORM\Entity()
*/
class Project
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, unique=true, nullable=false)
*/
private $project_nr;
/**
* @ORM\ManyToOne(targetEntity="Pso\ProjectBundle\Entity\Mandator",
inversedBy="projects")
* @ORM\JoinColumn(name="mandator_id", referencedColumnName="id")
*/
private $mandator;
/**
* @ORM\Column(type="string", length=80, nullable=false)
*/
private $project_name;
/**
* @ORM\Column(type="string", length=50)
*/
private $customer;
/**
* @ORM\Column(type="string", length=50)
*/
private $label;
/**
* @ORM\Column(type="date")
*/
private $shipping_date;
/**
* @ORM\Column(type="float")
*/
private $advance_payment;
/**
* @ORM\Column(type="integer", length=1)
*/
private $probability;
/**
* @ORM\Column(type="blob")
*/
private $special_demand;
/**
* @ORM\Column(type="string", length=4)
*/
private $currency;
/**
* @ORM\Column(type="integer", length=1, nullable=false)
*/
private $status;
/**
* @ORM\Column(type="string", length=100)
*/
private $contract_nr;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $dbinsert;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $dbupdate;
/**
* @ORM\ManyToMany(targetEntity="Pso\LogBundle\Entity\User", cascade=
{"persist", "remove"})
*/
private $users;
public function __construct() {
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
}
}
When I now try to generate setters and getters with command
app/console doctrine:generate:entities ProjectBundle/Entity/Mandator
or
app/console doctrine:generate:entities ProjectBundle/Entity/Project
I get the error
[RuntimeException] Namespace "ProjectBundle\Entity\Mandator" does not contain any mapped
entities.
I read several topics for example (topic 1, topic2, topic 3) without an idea, where my mistake could be.
Upvotes: 1
Views: 528
Reputation: 7163
It looks like you forgot the root part of your namespace 'Pso'.
You have to execute :
app/console doctrine:generate:entities Pso/ProjectBundle/Entity/Mandator
Upvotes: 0