我创建了Formtype UniversitaireType但是我有这个错误:
attribut condidat_id在我尝试命令php bin / console doctrine时没有在数据库中创建:schema:update --force(所有attributs在数据库中创建除了id_condidat)..我在实体Universitaire中映射OneToMany $ condidat < / p>
代码实体:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\Condidat;
/**
* Universitaire.
*
* @ORM\Table(name="universitaires")
* @ORM\Entity(repositoryClass="AppBundle\Entity\UniversitaireEntityRepository")
*/
class Universitaire
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="date_start", type="string", length=255, nullable=true)
*/
private $dateStart;
/**
* @var string
*
* @ORM\Column(name="date_end", type="string", length=255, nullable=true)
*/
private $dateEnd;
/**
* @var string
*
* @ORM\Column(name="establishment", type="string", length=255, nullable=true, unique=true)
*/
private $establishment;
/**
* @var string
*
* @ORM\Column(name="diploma", type="string", length=255, nullable=true, unique=true)
*/
private $diploma;
/**
*@ORM\OneToMany(targetEntity="AppBundle\Entity\Condidat",mappedBy="id_universitaire",cascade={"persist"})
*@ORM\JoinColumn(name="id_condidat", referencedColumnName="id")
*/
private $condidat;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Add Condidat
*
* @param \AppBundle\Entity\Condidat $condidat
* @return Universitaire
*/
public function addCondidat(\AppBundle\Entity\Condidat $condidat)
{
$this->condidat[] = $condidat;
return $this;
}
/**
* Remove Condidat
*
* @param \AppBundle\Entity\Condidat $condidat
*/
public function removeCondidat(\AppBundle\Entity\Condidat $condidat)
{
$this->Condidat->removeElement($condidat);
}
/**
* Get Condidat
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCondidat()
{
return $this->condidat;
}
/**
* Set dateStart.
*
* @param string $dateStart
*
* @return Universitaire
*/
public function setdateStart($dateStart)
{
$this->dateStart = $dateStart;
return $this;
}
/**
* Get dateStart.
*
* @return string
*/
public function getdateStart()
{
return $this->dateStart;
}
/**
* Set dateEnd.
*
* @param string $dateEnd
*
* @return Universitaire
*/
public function setDateEnd($dateEnd)
{
$this->dateEnd = $dateEnd;
return $this;
}
/**
* Get dateEnd.
*
* @return string
*/
public function getdateEnd()
{
return $this->dateEnd;
}
/**
* Set establishment.
*
* @param string $establishment
*
* @return Universitaire
*/
public function setEstablishment($establishment)
{
$this->establishment = $establishment;
return $this;
}
/**
* Get establishment.
*
* @return string
*/
public function getEstablishment()
{
return $this->establishment;
}
/**
* Set diploma.
*
* @param string $diploma
*
* @return Universitaire
*/
public function setDiploma($diploma)
{
$this->diploma = $diploma;
return $this;
}
/**
* Get diploma.
*
* @return string
*/
public function getDiploma()
{
return $this->diploma;
}
public function __construct()
{
$this->ResponsableCategory = new \Doctrine\Common\Collections\ArrayCollection();
}
}
代码FormType:
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use AppBundle\Entity\Universitaire;
use AppBundle\Entity\Condidat;
class UniversitaireType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('dateStart')->add('dateEnd')->add('establishment')->add('diploma')
->add('condidat',null, array(
'class' => 'AppBundle:Condidat',
'choice_label' => 'condidat',));
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Universitaire',
"csrf_protection" => "false"
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'appbundle_universitaire';
}
}
答案 0 :(得分:0)
你的&#34; condidat&#34;你有两个错误。属性。
您使用了一对多(双向)。如果你想只有一个 候选人&#34; Universitaire&#34; - 然后你必须使用一对一(双向)。
import os
import time
import hashlib
class SimpleFileCheckSum(object):
def __init__(self, path):
self.path = path
self.output = {}
def check_path_error(self):
if os.path.exists(self.path) is True and os.path.isfile(self.path):
return True
else:
return False
def get_file_size(self):
try:
st_data = os.stat(self.path)
get_size = str(st_data.st_size)
except PermissionError:
try:
os_size_data = str(os.path.getsize(self.path))
self.output["SIZE"] = os_size_data
except:
self.output["SIZE"] = "Error"
else:
self.output["SIZE"] = get_size
def get_file_times(self):
def convert_time_to_human_readable(get_time):
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(get_time))
try:
my_st_object = os.stat(self.path)
file_creation_time = convert_time_to_human_readable(my_st_object.st_ctime)
file_last_modified_time = convert_time_to_human_readable(my_st_object.st_mtime)
except:
self.output['TIMES'] = {"CREATION": "Error", "MODIFIED": "Error"}
else:
self.output['TIMES'] = {"CREATION": file_creation_time, "MODIFIED": file_last_modified_time}
def get_file_full_path(self):
try:
get_full_path = os.path._getfullpathname(self.path)
get_final_path = os.path._getfinalpathname(self.path)
except:
self.output['PATH'] = {"FULL": "Error", "FINAL": "Error"}
else:
self.output['PATH'] = {"FULL": get_full_path, "FINAL": get_final_path}
def get_file_hashes(self):
try:
hash_md5 = hashlib.md5()
hash_sha1 = hashlib.sha1()
hash_sha256 = hashlib.sha256()
hash_sha512 = hashlib.sha512()
with open(self.path, "rb") as f:
for chunk in iter(lambda: f.read(2 ** 20), b""):
hash_md5.update(chunk)
hash_sha1.update(chunk)
hash_sha256.update(chunk)
hash_sha512.update(chunk)
except:
self.output["HASH"] = {"MD5": "Error", "SHA1": "Error", "SHA256": "Error", "SHA512": "Error"}
else:
self.output["HASH"] = {"MD5": hash_md5.hexdigest(), "SHA1": hash_sha1.hexdigest(),
"SHA256": hash_sha256.hexdigest(), "SHA512": hash_sha512.hexdigest()}
def call_all(self):
if self.check_path_error() is True:
self.get_file_full_path()
self.get_file_size()
self.get_file_times()
self.get_file_hashes()
return self.output
else:
return {"Error": "Your Path is Not Valid"}
if __name__ == '__main__':
file_info = SimpleFileCheckSum("Your_file_address")
get_last_data = file_info.call_all()
print("Your Raw Dict Output : ", get_last_data, "\n\n")
如果没有,而且一对多就是你想拥有的,那么你必须在class Universitaire
{
## ...
/**
* Bidirectional One-To-One (Owning Side)
*
* @ORM\OneToOne(
* targetEntity="AppBundle\Entity\Condidat",
* inversedBy="universitaire",
* cascade={"persist", "remove"}
* )
* @ORM\JoinColumn(
* name="condiat_id",
* referencedColumnName="id"
* )
*/
private $condidat;
class Condidat
{
## ...
/**
* Bidirectional One-To-One (Inversed Side)
*
* @ORM\OneToOne(
* targetEntity="AppBundle\Entity\Universitaire",
* mappedBy="condidat",
* )
*/
private $universitaire;
中设置&#34; condidat&#34;是一个数组集合
__construct()
如果我是你,我宁愿使用&#34;候选人&#34;用&#34; s&#34; - 显示,这是一个arrayCollection。
正如我已经说过的那样 - 你的例子是双向一对多。在这种情况下,我们使用mappedBy和inversedBy。您在其中设置加入列的实体是拥有方。当然,JoinColumn必须在&#34; Candidate&#34;实体。所以:
public function __construct()
{
$this->condidat = new \Doctrine\Common\Collections\ArrayCollection();
}
我添加了class Universitaire
{
## ...
/**
* Bidirectional One-To-Many (Owning Side)
* Predicate: One Universitaire can have a lot of candidates
*
* @ORM\OneToMany(
* targetEntity="AppBundle\Entity\Condidat",
* mappedBy="universitaire",
* cascade={"persist", "remove"}
* )
*/
private $condidats;
class Condidat
{
## ...
/**
* Bidirectional Many-To-One (Owning Side)
* Predicate: Each Condidat belongs to one Universitaire
*
* @ORM\ManyToOne(
* targetEntity="AppBundle\Entity\Universitaire",
* inversedBy="condidats",
* )
* @ORM\JoinColumn(
* name="universitaire_id",
* referencedColumnName="id",
* onDelete="SET NULL"
* )
*/
private $universitaire;
。如果你删除了universitaire,那么在每个&#34; condidate&#34;的字段统计中。你会看到空值。