The error I get is:
我得到的错误是:
Found entity of type Doctrine\Common\Collections\ArrayCollection on association model\StoreBundle\Entity\campaign#campaignOperatingSystems, but expecting model\StoreBundle\Entity\campaignOS
在关联模型\ StoreBundle \ Entity \ campaign#campaignOperatingSystems上找到Doctrine \ Common \ Collections \ ArrayCollection类型的实体,但期望model \ StoreBundle \ Entity \ campaignOS
Here is campaignOS summerized:
这是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;
}
}
Campaign summarized:
活动摘要:
/**
* 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;
}
}
This is what displays and persists:
这是显示和持续的内容:
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(),
));
}
Here is the stack trace: Stack Trace
这是堆栈跟踪:堆栈跟踪
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))
1 个解决方案
#1
0
The signature of these methods
这些方法的签名
public function addCampaignOperatingSystem(\model\StoreBundle\Entity\campaignOS $campaignOperatingSystems)
public function removeCampaignOperatingSystem(\model\StoreBundle\Entity\campaignOS $campaignOperatingSystems)
Says that you expect, in input, a single object of type campaignOS but you're passing to one of these an ArrayCollection (of campaignOS
, I suppose).
假设你在输入中期望一个类型为campaignOS的单个对象,但你要传递给其中一个ArrayCollection(我认为是campaignOS)。
So the error is into signature or - probably - into your logic.
所以错误是签名或 - 可能 - 进入你的逻辑。
Maybe you want an operation like setCompaignOperationSystem
?
也许你想要一个像setCompaignOperationSystem这样的操作?
#1
0
The signature of these methods
这些方法的签名
public function addCampaignOperatingSystem(\model\StoreBundle\Entity\campaignOS $campaignOperatingSystems)
public function removeCampaignOperatingSystem(\model\StoreBundle\Entity\campaignOS $campaignOperatingSystems)
Says that you expect, in input, a single object of type campaignOS but you're passing to one of these an ArrayCollection (of campaignOS
, I suppose).
假设你在输入中期望一个类型为campaignOS的单个对象,但你要传递给其中一个ArrayCollection(我认为是campaignOS)。
So the error is into signature or - probably - into your logic.
所以错误是签名或 - 可能 - 进入你的逻辑。
Maybe you want an operation like setCompaignOperationSystem
?
也许你想要一个像setCompaignOperationSystem这样的操作?