当我坚持对象邀请时,我有这个错误..我在邀请和候选人之间制作实体邀请内容映射...邀请中的ManyToOne和候选人中的OneToMany但是我有这个错误:
类型" AppBundle \ Entity \ Candidate"的预期值for association field" AppBundle \ Entity \ Invitation#$ candidate",got" Doctrine \ Common \ Collections \ ArrayCollection"代替。
代码邀请
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use AppBundle\Model\RecruiterInterface;
use AppBundle\Model\CandidateInterface;
use AppBundle\Entity\Recruiter;
use AppBundle\Entity\Candidate;
use AppBundle\Entity\OfferSkill;
/**
* Invitation
*
* @ORM\Table(name="invitation")
* @ORM\Entity(repositoryClass="AppBundle\Repository\InvitationRepository")
*/
class Invitation
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var RecruiterInterface
*
* @ORM\ManyToOne(targetEntity="Recruiter", inversedBy="invitations")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="recruiter_id", referencedColumnName="id")
* })
*/
private $recruiter;
/**
* @var CandidateInterface
*
* @ORM\ManyToOne(targetEntity="Candidate", inversedBy="invitations")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="candidate_id", referencedColumnName="id")
* })
*/
private $candidate;
/**
* @var OfferSkill
*
* @ORM\ManyToOne(targetEntity="OfferSkill", inversedBy="invitations")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="offerskill_id", referencedColumnName="id")
* })
*/
private $offerSkill;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
public function __construct()
{
$this->candidate = new ArrayCollection();
}
/**
* Set recruiter.
*
* @param \AppBundle\Entity\Recruiter $recruiter
*
* @return Invitation
*/
public function setRecruiter(\AppBundle\Entity\Recruiter $recruiter = null)
{
$this->recruiter = $recruiter;
return $this;
}
/**
* Get recruiter.
*
* @return \AppBundle\Entity\Recruiter
*/
public function getRecruiter()
{
return $this->recruiter;
}
/**
* Set candidate.
*
* @param \AppBundle\Entity\Candidate $candidate
*
* @return Invitation
*/
public function setCandidate(\AppBundle\Entity\Candidate $candidate = null)
{
$this->candidate = $candidate;
return $this;
}
/**
* Get candidate.
*
* @return \AppBundle\Entity\Candidate
*/
public function getCandidate()
{
return $this->candidate;
}
/**
* Set offerSkill.
*
* @param \AppBundle\Entity\OfferSkill $offerSkill
*
* @return Invitation
*/
public function setOfferSkill(\AppBundle\Entity\OfferSkill $offerSkill = null)
{
$this->offerSkill = $offerSkill;
return $this;
}
/**
* Get offerSkill.
*
* @return \AppBundle\Entity\OfferSkill
*/
public function getOfferSkill()
{
return $this->offerSkill;
}
}
候选人中的部分映射:
/**
* @var Invitation[]
*
* @ORM\OneToMany(targetEntity="Invitation", mappedBy="candidate", cascade={"persist","remove"})
* @Assert\Count(min = 1)
*/
private $invitations;
/**
* Add invitation.
*
* @param Invitation $invitation
*
* @return RecruiterInterface
*/
public function addInvitation(Invitation $invitation): CandidateInterface
{
$this->invitations[] = $invitation;
return $this;
}
/**
* Remove invitation.
*
* @param Invitation $invitation
*/
public function removeInvitation(Invitation $invitation)
{
$this->invitations->removeElement($invitation);
}
/**
* @return Collection
*/
public function getInvitation()
{
return $this->invitations;
}
代码表格类型:
<?php
namespace AppBundle\Form\Type;
use AppBundle\Entity\Invitation;
use AppBundle\Entity\Candidate;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
/**
* Class InvitationType.
*/
class InvitationType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('candidate', EntityType::class, [
'class' => Candidate::class,
'choice_label' => 'Username',
'required' => true,
'multiple' => true,
])
->add('Create', SubmitType::class, array('attr' => array('class' => 'experience btn btn-fill btn-rose')))
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Invitation::class,
'allow_extra_fields' => true,
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return '';
}
}
代码控制器:
public function newAction($id,Request $request) {
try
{
$offer = $this->getDoctrine()->getRepository(OfferSkill::class)->findOneBy(['id'=>$id]);
$invitation = $this->getHandler()->invitation($offer, $request->request->all(), $request->isMethod(Request::METHOD_POST));
if ($invitation instanceOf Invitation) {
$url = $this->generateUrl('homepage');
return new RedirectResponse($url);
}
}
catch(InvalidFormException $e) {
return [
'form' => $e->getForm()->createView(),
'edit' => false,
];
}
return ['form' => $invitation->createView()];
}
现在我选择了多个候选人,但我有这个错误
答案 0 :(得分:1)
您无法在# build data
from StringIO import StringIO
import pandas as pd
df = pd.read_csv(StringIO("""Cliente,Fecha,Auth_domain,Sitio,Country,ECPM_medio
FF,15/12/2017,@ff,ff_Color,Afganistán,0.53
FF,15/01/2018,@ff,ff_Color,Afganistán,0.5
FF,15/01/2017,@ff,ff_Color,Alemania,0.34
FF,15/12/2017,@ff,ff_Color,Alemania,0.38
FF,15/01/2018,@ff,ff_Color,Alemania,0.37
""")).sort_values(by='Fecha')
# functions to parse
def compare_val(cur,past,future):
if cur <= past:
cur_adj = cur * .8
if cur_adj >= past:
return(past)
else:
return(cur_adj)
else:
if future >= past:
return(past)
else:
return(future)
def setval(v):
cur, past, future = v, v.shift(-1), v.shift(1)
v = [ compare_val(*x) for x in zip(cur,past,future)]
return(v)
# do the work
df['Recomendation_ECPM'] = df.\
groupby(['Cliente','Auth_domain','Sitio',"Country"])['ECPM_medio'].\
transform(setval)
df[ pd.notna(df['Recomendation_ECPM']) ]
中设置multiple => true
,因为InvitationType
和ManyToOne
之间的关系为Candidate
因此,您需要删除Invitation
选项或将关系更改为实体中的multiple