私が得るエラーは次のとおりです。
アソシエーションmodel\StoreBundle \ Entity \ campaign#campaignOperatingSystemsでタイプDoctrine \ Common \ Collections \ ArrayCollectionのエンティティが見つかりましたが、model \ StoreBundle \ Entity\campaignOSが必要です
これがcampaignOSの要約です。
/**
* model\StoreBundle\Entity\campaignOS
* @ORM\Table(name="campaign_os")
* @ORM\Entity
*/
class campaignOS extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('OS', 'entity', array(
'class' => 'modelStoreBundle:listOS',
'property' => 'OsName',
'multiple' => 'true',
'expanded' => 'true'
));
}
/**
* @var integer $id
*
* @ORM\Column(name="campaign_os_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
public function getId()
{
return $this->id;
}
/**
* @ORM\ManyToOne( targetEntity="campaign", inversedBy="campaignOperatingSystems" )
* @ORM\JoinColumn( name="campaign_os_id", referencedColumnName="campaign_id" )
*/
private $campaign;
public function setCampaign( \model\StoreBundle\Entity\campaign $ourCampaign )
{
$this->$campaign = $ourCampaign;
}
public function getCampaign()
{
return $this->$campaign;
}
/**
* @ORM\OneToOne( targetEntity="listOS" )
* @ORM\JoinColumn( name="campaign_os_id", referencedColumnName="os_id" )
*/
private $os;
public function setOS( \model\StoreBundle\Entity\listOS $campaignOS )
{
$this->os = $campaignOS;
}
public function getOS()
{
return $this->os;
}
}
キャンペーンの概要:
/**
* model\StoreBundle\Entity\campaign
*
* @ORM\Table(name="campaign")
* @ORM\Entity
*/
class campaign extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('Name', 'text', array( 'label' => 'Campaign Name' ));
//$builder->add('CampaignDescription', 'textarea', array( 'label' => 'Campaign Description' ));
$builder->add('CampaignOperatingSystems', new campaignOS(), array( 'label' => 'Campaign OS' ));
/* $builder->add('CampaignOperatingSystems', 'entity', array(
'class' => 'modelStoreBundle:campaignOS',
'property' => 'OS.OsName',
'multiple' => 'true',
'expanded' => 'true',
'label' => 'Campaign OS'
)); */
}
/**
* @var integer $id
*
* @ORM\Column(name="campaign_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function __construct()
{
$this->campaignOperatingSystems = new ArrayCollection();
}
/**
* @ORM\OneToMany(targetEntity="campaignOS", mappedBy="campaign")
* * , cascade={"persist", "remove"})
* @var ArrayCollection $campaignOperatingSystems
*/
protected $campaignOperatingSystems;
public function addCampaignOperatingSystem(\model\StoreBundle\Entity\campaignOS $campaignOperatingSystems)
{
$this->campaignOperatingSystems[] = $campaignOperatingSystems;
/* foreach( $campaignOperatingSystems as $campaignOS )
{
$campaignOS->setCampaign( $this );
} */
return $this;
}
public function removeCampaignOperatingSystem(\model\StoreBundle\Entity\campaignOS $campaignOperatingSystems)
{
$this->campaignOperatingSystems->removeElement($campaignOperatingSystems);
}
public function getCampaignOperatingSystems()
{
return $this->campaignOperatingSystems;
}
}
これが表示され、持続するものです。
public function newAction( Request $request )
{
//create a campaign
$campaign = new campaign();
// get the form
$form = $this->createForm( new campaign(), $campaign );
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
// perform some action, such as saving the task to the database
//get our data manager
$em = $this->getDoctrine()->getManager();
//make it presistent
$em->persist($campaign);
//update the DB
$em->flush();
return $this->redirect($this->generateUrl('displayDB'));
}
}
return $this->render('modelStoreBundle:DisplayDB:newCampaign.html.twig', array(
'form' => $form->createView(),
));
}
スタックトレースは次のとおりです。スタックトレース
in /vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 753
$state = $this->getEntityState($entry, self::STATE_NEW);
if ( ! ($entry instanceof $assoc['targetEntity'])) {
throw new ORMException(
sprintf(
'Found entity of type %s on association %s#%s, but expecting %s',
get_class($entry),
at UnitOfWork ->computeAssociationChanges (array('fieldName' => 'campaignOperatingSystems', 'mappedBy' => 'campaign', 'targetEntity' => 'model\StoreBundle\Entity\campaignOS', 'cascade' => array(), 'orphanRemoval' => false, 'fetch' => '2', 'type' => '4', 'inversedBy' => null, 'isOwningSide' => false, 'sourceEntity' => 'model\StoreBundle\Entity\campaign', 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false), object(PersistentCollection))
in /vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 651
at UnitOfWork ->computeChangeSet (object(ClassMetadata), object(campaign))
in /vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 383
at UnitOfWork ->computeScheduleInsertsChangeSets ()
in /vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 673
at UnitOfWork ->computeChangeSets ()
in /vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 273
at UnitOfWork ->commit (null)
in /vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php at line 355
at EntityManager ->flush (null)
in kernel.root_dir/cache/dev/jms_diextra/doctrine/EntityManager.php at line 362
at EntityManager ->flush ()
in /vagrant/src/model/StoreBundle/Controller/DisplayDBController.php at line 65
at DisplayDBController ->newAction (object(Request))