doctrine 相关问题

Doctrine Project是一个开源库和工具的集合,用于处理用PHP编写的数据库抽象和对象关系映射。

依赖注入通过 __construct() 到 Symfony/Doctrine EntityListener

我正在努力解决以下问题: 我为我的一个实体创建了一个 EntityListener。 命名空间 App\Event\EventListener\Vendor; 使用 App\Entity\Vendor; 使用 Doctrine\ORM\Event\

回答 2 投票 0

Doctrine FindBy DateTime 无限过程

当我想在我的 mysql 数据库中查询一行时,我遇到了问题。 'p_release_date' 字段是带有日期时间和原则的类型。插入后,格式为 2023-03-24 00:00:00。 当我点击 o...

回答 0 投票 0

Doctrine 能否用开箱即用的自定义标量值(例如聚合、CASE 结果等)滋润我的实体?

如果我有一个 Querybuilder 实例并应用如下内容: $queryBuilder->addSelect(" 案件 当 c.modifyStamp > c.createStamp THEN '草稿' 否则“已发布” 结束为...

回答 2 投票 0

在 Doctrine 2 中以编程方式执行迁移

鉴于我有通往 Doctrine 迁移课程的途径。我如何在 Doctrine 2 中以编程方式执行迁移? 我认为应该有一种干净的方法来通过 API 执行迁移

回答 3 投票 0

Symfony 类型为“?App\Entity\ProductPriceOptions”的预期参数,“字符串”给定

我的问题如下所示。 我尝试创建一个表格,您可以在其中选择所需产品的包装,然后在拥有时将其上传到购物车,但是有一个

回答 0 投票 0

Symfony - 一对多,一个活跃

我想问一下在 Symfony 中最好的方法是什么。 例如。有一个实体用户与另一个实体地址具有一对多关系。 假设用户可以多次交付

回答 1 投票 0

如何在配置中添加从包到主应用程序的迁移路径

我又来求助了。 我正在开发几个 Symfony 6.2 应用程序,它们之间共享大量代码。所以,我把一堆放在捆绑上。到目前为止它正在工作,包括

回答 0 投票 0

Symfony Doctrine 原始 SQL 返回“SQLSTATE[IMSSP]:查询的活动结果不包含任何字段。”

我尝试使用 Symfony 中的 Doctrine 将以下查询发送到 MSSQL 服务器: 声明@ebayitems 表(kartikel INT,cartnr VARCHAR(255),ebayPrice DECIMAL(10,2),ebayID VARCHAR(255)) 声明@

回答 0 投票 0

Symfony 6 + Doctrine - 如何配置 Doctrine\DBAL\Driver\OCI8\Middleware\InitializeSession?

Doctrine\DBAL\Event\Listeners\OracleSessionInit 在 DBAL 3.5 (https://github.com/doctrine/dbal/blob/3.5.x/UPGRADE.md) 中被弃用,取而代之的是 Doctrine\DBAL\Driver \OCI8\中间件\

回答 1 投票 0

Laravel 使用错误的学说实体代理

我有一个奇怪的问题。我有两个 Laravel 项目,一个在 /var/www/vhosts/production 中,一个在 /var/www/vhosts/test 中。这些几乎是一样的。他们有不同的环境变量 - production vs

回答 0 投票 0

我不知道如何面对这个错误:在 Symfony 6 项目的链配置命名空间 App\Entity 中找不到类“DateTime”

以下错误消息属于“MappingException”类型。当我尝试在 verifBan 函数中使用 entityManager 的 remove() 函数时出现: 禁止存储库: 以下错误消息属于“MappingException”类型。当我尝试在 verifBan 函数中使用 entityManager 的 remove() 函数时出现: 禁止存储库: <?php namespace App\Repository; use App\Entity\Bannissement; use App\Entity\Utilisateur; use DateTime; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; /** * @extends ServiceEntityRepository<Bannissement> * * @method Bannissement|null find($id, $lockMode = null, $lockVersion = null) * @method Bannissement|null findOneBy(array $criteria, array $orderBy = null) * @method Bannissement[] findAll() * @method Bannissement[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class BannissementRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Bannissement::class); } public function save(Bannissement $entity, bool $flush = false): void { $this->getEntityManager()->persist($entity); if ($flush) { $this->getEntityManager()->flush(); } } public function remove(Bannissement $entity, bool $flush = false): void { $this->getEntityManager()->remove($entity); if ($flush) { $this->getEntityManager()->flush(); } } // /** // * @return Bannissement[] Returns an array of Bannissement objects // */ // public function findByExampleField($value): array // { // return $this->createQueryBuilder('b') // ->andWhere('b.exampleField = :val') // ->setParameter('val', $value) // ->orderBy('b.id', 'ASC') // ->setMaxResults(10) // ->getQuery() // ->getResult() // ; // } // public function findOneBySomeField($value): ?Bannissement // { // return $this->createQueryBuilder('b') // ->andWhere('b.exampleField = :val') // ->setParameter('val', $value) // ->getQuery() // ->getOneOrNullResult() // ; // } public function verifBan(Utilisateur $user){ $now = new DateTime(); $endBan = $user->getBanRecu()->getDateTimeFin(); if($endBan){ if($now > $endBan){ $em = $this->getEntityManager(); $em->remove($endBan); $em->flush(); return true; }else{ return false; } }else{ return true; } } } verifBan 函数检查用户是否有禁令,并将禁令的结束日期与当前日期进行比较。 当用户的禁令仍在进行中时,一切都会正常进行。但是一过ban,必须删除,就报错了。 这是禁令实体: <?php namespace App\Entity; use App\Repository\BannissementRepository; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: BannissementRepository::class)] class Bannissement { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column(type: Types::TEXT)] private ?string $raison = null; #[ORM\ManyToOne(inversedBy: 'banCrees')] #[ORM\JoinColumn(nullable: false)] private ?Utilisateur $banneur = null; #[ORM\OneToOne(inversedBy: 'banRecu', cascade: ['persist', 'remove'])] #[ORM\JoinColumn(nullable: false)] private ?Utilisateur $banni = null; #[ORM\Column(type: Types::DATETIME_MUTABLE)] private ?\DateTimeInterface $dateTimeFin = null; public function getId(): ?int { return $this->id; } public function getRaison(): ?string { return $this->raison; } public function setRaison(string $raison): self { $this->raison = $raison; return $this; } public function getBanneur(): ?Utilisateur { return $this->banneur; } public function setBanneur(?Utilisateur $banneur): self { $this->banneur = $banneur; return $this; } public function getBanni(): ?Utilisateur { return $this->banni; } public function setBanni(Utilisateur $banni): self { $this->banni = $banni; return $this; } public function getDateTimeFin(): ?\DateTimeInterface { return $this->dateTimeFin; } public function setDateTimeFin(\DateTimeInterface $dateTimeFin): self { $this->dateTimeFin = $dateTimeFin; return $this; } } 和用户实体: <?php namespace App\Entity; use App\Repository\UtilisateurRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use phpDocumentor\Reflection\Types\Boolean; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; #[ORM\Entity(repositoryClass: UtilisateurRepository::class)] #[UniqueEntity(fields: ['pseudo'], message: 'There is already an account with this pseudo')] class Utilisateur implements UserInterface, PasswordAuthenticatedUserInterface { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column(length: 180, unique: true)] private ?string $pseudo = null; #[ORM\Column(length: 180)] private string $email; #[ORM\Column] private array $roles = []; /** * @var string The hashed password */ #[ORM\Column] private ?string $password = null; #[ORM\OneToMany(mappedBy: 'Utilisateur', targetEntity: QuizzEffectue::class, orphanRemoval: true)] private Collection $quizzEffectues; #[ORM\Column(type: 'boolean')] private $is_verified = false; #[ORM\Column(type: 'string', length: 100)] private $resetToken; #[ORM\ManyToMany(targetEntity: Proposition::class, inversedBy: 'utilisateurs')] private Collection $propositions; #[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'estAmisDe')] private Collection $amis; #[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'amis')] private Collection $estAmisDe; #[ORM\OneToMany(mappedBy: 'utilisateur', targetEntity: Notification::class, orphanRemoval: true)] private Collection $notifications; #[ORM\OneToMany(mappedBy: 'envoyeur', targetEntity: Message::class, orphanRemoval: true)] private Collection $messagesEnvoyes; #[ORM\OneToMany(mappedBy: 'destinataire', targetEntity: Message::class)] private Collection $messagesRecus; #[ORM\OneToMany(mappedBy: 'banneur', targetEntity: Bannissement::class, orphanRemoval: true)] private Collection $banCrees; #[ORM\OneToOne(mappedBy: 'banni', cascade: ['persist', 'remove'])] #[ORM\JoinColumn(nullable: true)] private ?Bannissement $banRecu = null; public function __construct() { $this->quizzEffectues = new ArrayCollection(); $this->propositions = new ArrayCollection(); $this->amis = new ArrayCollection(); $this->estAmisDe = new ArrayCollection(); $this->notifications = new ArrayCollection(); $this->messagesEnvoyes = new ArrayCollection(); $this->messagesRecus = new ArrayCollection(); $this->banCrees = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getPseudo(): ?string { return $this->pseudo; } public function setPseudo(string $pseudo): self { $this->pseudo = $pseudo; return $this; } /** * A visual identifier that represents this user. * * @see UserInterface */ public function getUserIdentifier(): string { return (string) $this->pseudo; } public function getEmail(): ?string{ return $this->email; } public function setEmail(?string $email): self { $this->email = $email; return $this; } /** * @see UserInterface */ public function getRoles(): array { $roles = $this->roles; // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; return array_unique($roles); } public function setRoles(array $roles): self { $this->roles = $roles; return $this; } /** * @see PasswordAuthenticatedUserInterface */ public function getPassword(): string { return $this->password; } public function setPassword(string $password): self { $this->password = $password; return $this; } /** * @see UserInterface */ public function eraseCredentials() { // If you store any temporary, sensitive data on the user, clear it here // $this->plainPassword = null; } /** * @return Collection<int, QuizzEffectue> */ public function getQuizzEffectues(): Collection { return $this->quizzEffectues; } public function addQuizzEffectue(QuizzEffectue $quizzEffectue): self { if (!$this->quizzEffectues->contains($quizzEffectue)) { $this->quizzEffectues->add($quizzEffectue); $quizzEffectue->setUtilisateur($this); } return $this; } public function removeQuizzEffectue(QuizzEffectue $quizzEffectue): self { if ($this->quizzEffectues->removeElement($quizzEffectue)) { // set the owning side to null (unless already changed) if ($quizzEffectue->getUtilisateur() === $this) { $quizzEffectue->setUtilisateur(null); } } return $this; } public function getIsVerified(): ?bool { return $this->is_verified; } public function setIsVerified(bool $is_verified): self { $this->is_verified = $is_verified; return $this; } public function getResetToken(): ?string { return $this->resetToken; } public function setResetToken(?string $resetToken): self { $this->resetToken = $resetToken; return $this; } /** * @return Collection<int, Proposition> */ public function getPropositions(): Collection { return $this->propositions; } public function addProposition(Proposition $proposition): self { if (!$this->propositions->contains($proposition)) { $this->propositions->add($proposition); } return $this; } public function removeProposition(Proposition $proposition): self { $this->propositions->removeElement($proposition); return $this; } /** * @return Collection<int, self> */ public function getAmis(): Collection { return $this->amis; } public function addAmi(self $ami): self { if (!$this->amis->contains($ami)) { $this->amis->add($ami); } return $this; } public function removeAmi(self $ami): self { $this->amis->removeElement($ami); return $this; } /** * @return Collection<int, self> */ public function getEstAmisDe(): Collection { return $this->estAmisDe; } public function addEstAmisDe(self $estAmisDe): self { if (!$this->estAmisDe->contains($estAmisDe)) { $this->estAmisDe->add($estAmisDe); $estAmisDe->addAmi($this); } return $this; } public function removeEstAmisDe(self $estAmisDe): self { if ($this->estAmisDe->removeElement($estAmisDe)) { $estAmisDe->removeAmi($this); } return $this; } /** * @return Collection<int, Notification> */ public function getNotifications(): Collection { return $this->notifications; } public function addNotification(Notification $notification): self { if (!$this->notifications->contains($notification)) { $this->notifications->add($notification); $notification->setUtilisateur($this); } return $this; } public function removeNotification(Notification $notification): self { if ($this->notifications->removeElement($notification)) { // set the owning side to null (unless already changed) if ($notification->getUtilisateur() === $this) { $notification->setUtilisateur(null); } } return $this; } /** * @return Collection<int, Message> */ public function getMessagesEnvoyes(): Collection { return $this->messagesEnvoyes; } public function addMessagesEnvoye(Message $messagesEnvoye): self { if (!$this->messagesEnvoyes->contains($messagesEnvoye)) { $this->messagesEnvoyes->add($messagesEnvoye); $messagesEnvoye->setEnvoyeur($this); } return $this; } public function removeMessagesEnvoye(Message $messagesEnvoye): self { if ($this->messagesEnvoyes->removeElement($messagesEnvoye)) { // set the owning side to null (unless already changed) if ($messagesEnvoye->getEnvoyeur() === $this) { $messagesEnvoye->setEnvoyeur(null); } } return $this; } /** * @return Collection<int, Message> */ public function getMessagesRecus(): Collection { return $this->messagesRecus; } public function addMessagesRecu(Message $messagesRecu): self { if (!$this->messagesRecus->contains($messagesRecu)) { $this->messagesRecus->add($messagesRecu); $messagesRecu->setDestinataire($this); } return $this; } public function removeMessagesRecu(Message $messagesRecu): self { if ($this->messagesRecus->removeElement($messagesRecu)) { // set the owning side to null (unless already changed) if ($messagesRecu->getDestinataire() === $this) { $messagesRecu->setDestinataire(null); } } return $this; } /** * @return Collection<int, Bannissement> */ public function getBanCrees(): Collection { return $this->banCrees; } public function addBanCree(Bannissement $banCree): self { if (!$this->banCrees->contains($banCree)) { $this->banCrees->add($banCree); $banCree->setBanneur($this); } return $this; } public function removeBanCree(Bannissement $banCree): self { if ($this->banCrees->removeElement($banCree)) { // set the owning side to null (unless already changed) if ($banCree->getBanneur() === $this) { $banCree->setBanneur(null); } } return $this; } public function getBanRecu(): ?Bannissement { return $this->banRecu; } public function setBanRecu(Bannissement $banRecu): self { // set the owning side of the relation if necessary if ($banRecu->getBanni() !== $this) { $banRecu->setBanni($this); } $this->banRecu = $banRecu; return $this; } } 我已经尝试找到解决方案但没有成功,尤其是在这里 https://github.com/doctrine/orm/issues/8366 但不了解他们的工作。 我提前谢谢你 DateTime 在全局命名空间中。添加一个像 \DateTime 这样的斜杠,或者使用 use 语句导入它。

回答 1 投票 0

如何根据额外字段从多对多 Doctrine 关联中过滤返回的对象

假设我想链接两个表:CHILD(ren) 到他们的 PARENT(s),通过联合表 ROLE 进行多对多关联 在 CHILD 实体的映射中,这是我要放置的内容: /** * @var

回答 1 投票 0

Symfony Doctrine SQLSTATE 42S02 Base Table or View not found

我在 Symfony Bundle 类中使用它创建了一个带有 Doctrine 的表: 我在 Symfony Bundle 类中使用这个创建了一个带有 Doctrine 的表: <?php namespace Acme\Bundle\TranslationMessagesProducerBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * * @ORM\Entity * @ORM\Table(name="acme_translation_config") * */ class AcmeTranslationMessagesProducerEntity{ /** * id - for doctrine * @ORM\Column(type="integer") * @ORM\Id() * @var integer */ private $id; /** * enabled * @ORM\Column(type="boolean") * @var mixed */ private $enabled; public function getId(){ return $this->id; } public function getEnabled(){ return $this->enabled; } } 运行后这张表存在 php bin/console doctrine:schema:update --force 我可以通过查询验证它是否存在 php bin/console doctrine:query:sql "Select * From acme_translation_config 或者也运行: php bin/console doctrine:query:sql "Select * From akeneo_pim.acme_translation_config Doctrine 也能识别它,通过运行验证: php bin/console doctrine:mapping:info 结果: Found 58 mapped entities: .... Acme\Bundle\TranslationMessagesProducerBundle\Entity\AcmeTranslationMessagesProducerEntity 但是,如果我像这样从这张表中获取一个对象: $em = $this->getDoctrine()->getManager(); $config = $em->getRepository(AcmeTranslationMessagesProducerEntity::class)->find(1); 我失败了: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'akeneo_pim.acme_translation_config' doesn't exist 如何解决这个问题?

回答 0 投票 0

Doctrine 2 - 如何在没有递归的情况下将整个数据集加载到无向图的缓存中?

我认为我们有一个实体 Foo 的用例,它可以有任意数量的父 Foos 和子 Foos。这是通过具有

回答 1 投票 0

如果既不在迁移也不在 dataFixtures 中,在 symfony 应用程序中在哪里添加基本通用数据?

在使用 doctrine 的 Symfony 应用程序中,建议通过迁移构建和更新模式(来源)。 然而,为了测试目的添加假数据,建议您使用 DataFixtu ...

回答 0 投票 0

数据库架构创建 - 没有传输支持给定的 Messenger DSN“”

Symfony 5.4 - 尝试将我们的邮件库升级到 Symfony Mailer。 CI 的 phpunit 阶段创建测试数据库模式失败,出现以下错误: $ php bin/console 学说:...

回答 0 投票 0

如何在 Symfony 5 迁移中使用容器(和服务)?

我正在尝试在迁移中获取容器和通过它的服务(使用 Symfony 5.1.2 和 doctrine/migrations 3.0.1)。但是当我尝试基于这个例子创建一个类时: cl...

回答 2 投票 0

收到警告:更新学说配置后“警告[缓存]无法保存密钥”

在尝试更新学说配置后,我收到警告:“警告 [缓存] 保存密钥失败”。当我运行 bin/console 时出现此错误。 我尝试将学说配置更新为 g...

回答 0 投票 0

Symfony 集合不保存数组但保存类名

我有带有 CollectionType 的 symfony 形式。这是一个多步骤表单,当我在每个步骤后转储数据时,它会正确保存: App\Entity\RezylientnaArchitektura {#654 ▼ -id: 空 -BezpInf:医生...

回答 0 投票 0

Doctrine:我应该为多对多关系创建一个中间实体吗?

在最近的会议上,我得到一个要求,对于所有的多对多关系,我们应该创建中间实体并具有多对一和一对多关系。 例如,我们有实体“U ...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.