doctrine-orm 相关问题

Doctrine ORM是一个PHP ORM。虽然Doctrine 1.2使用Active Record模式,但Doctrine ORM 2及更高版本使用Data Mapper模式。 Doctrine项目是一个开源库和工具的集合,用于处理用PHP编写的数据库抽象和对象关系映射。

如何避免与 Doctrine2 和 Zend Framework2 的 ManyToMany 关系重复?

目标是拥有 2 个实体文章和标签,具有多对多关系,其中标签表中的标签保持唯一,即使为其他文章声明相同的标签也是如此。 我尝试更好地解释...

回答 1 投票 0

Symfony2 原则错误:无法对使用 HAVING 子句的查询进行计数。使用输出步行器进行分页

我正在尝试获取非空的集合,即至少有 1 个对象。集合实体与对象实体具有一对多关系。我正在使用 KNP 分页器对结果进行分页。这是...

回答 4 投票 0

每个实体都必须有一个标识符/主键

有一个symfony项目,从5.1更新到6.4 LTS,并将原则更新到3.0.0。 将此实体从注释更新为 PHP8 属性: ` 有一个 symfony 项目,从 5.1 更新到 6.4 LTS,并将原则更新到 3.0.0。 将此实体从注释更新为 PHP8 属性: ` namespace App\Entity; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: "App\Repository\SottocontiUtentiRepository")] class SottocontiUtenti { #[ORM\Id] #[Column(type: "integer")] private int $utente_id; #[ORM\Id] #[Column(type: "integer")] private int $pratica_id; #[ORM\Id] #[Column(type: "integer")] private int $finanziamento_id; #[Column(type: "string")] private $nome; #[Column(type: "string")] private $cognome; // Ripristino della relazione #[ORM\ORM\Id()] #[ManyToOne(targetEntity: Sottoconti::class, inversedBy: "utenti")] #[JoinColumn(name: "sottoconto_id", referencedColumnName: "sottoconto_id", nullable: true)] private ?Sottoconti $sottoconto_id; // Nota l'utilizzo del tipo per Sottoconti #[Column(type: "float", nullable: true)] private $importo_deliberato; #[Column(type: "string", nullable: true)] private $rientro; public function getUtenteId(): ?int { return $this->utente_id; } public function setUtenteId(int $utente_id): self { $this->utente_id = $utente_id; return $this; } public function getSottocontoId(): ?Sottoconti { return $this->sottoconto_id; } public function setSottocontoId(?Sottoconti $sottoconto_id): self { $this->sottoconto_id = $sottoconto_id; return $this; } public function getPraticaId(): ?int { return $this->pratica_id; } public function setPraticaId(int $pratica_id): self { $this->pratica_id = $pratica_id; return $this; } public function getFinanziamentoId(): ?int { return $this->finanziamento_id; } public function setFinanziamentoId(int $finanziamento_id): self { $this->finanziamento_id = $finanziamento_id; return $this; } public function getImportoDeliberato(): ?float { return $this->importo_deliberato; } public function setImportoDeliberato(?float $importo_deliberato): self { $this->importo_deliberato = $importo_deliberato; return $this; } /** * @return mixed */ public function getRientro() { return $this->rientro; } /** * @param mixed $rientro */ public function setRientro($rientro): void { $this->rientro = $rientro; } } ` 出现此错误: 没有为实体“App\Entity\SottocontiUtenti”指定标识符/主键。每个实体都必须有一个标识符/主键。 尝试用 Google 搜索并询问 Gemini ADV 或 ChatGPT。 什么都不起作用。 也尝试过这种方式: https://www.doctrine-project.org/projects/doctrine-orm/en/3.0/tutorials/composite-primary-keys.html#composite-and-foreign-keys-as-primary-key 但仍然遇到同样的错误。 有什么建议吗? 非常感谢, 贾科莫。 看起来您缺少 importo_deliberato 表的实际主 id 字段,而且您应该只在主 id 字段而不是其他外部 id 中使用 #[ORM\Id]...这是取自 symfony 演示的示例应用程序: ... #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: 'integer')] private $id; #[ORM\ManyToOne(targetEntity: User::class)] #[ORM\JoinColumn(nullable: false)] private ?User $author = null; ...

回答 1 投票 0

Symfony 主义延迟加载属性

我有一个将大文件作为 blob 存储到数据库的实体。 我现在想让 Symfony 永远不会加载这些 blob,除非我通过适当的 getter 专门请求它们。 在埃森...

回答 2 投票 0

用 ORM 主义 symfony 显示大量数据

我尝试使用 symfony Web 应用程序进行充电测试。我有一个包含 13 个字段的实体,其中包括 1 个主键和 7 个外键。我已经注入了40K数据。 我的控制器使用 findAll() 和 KNP Paginator 机智...

回答 1 投票 0

改善导入数据时的内存使用

我实际上是在寻找建议,而不是解决方案。 我制作了一项服务,可以比较来自远程数据库的数据,并在必要时插入、更新或删除本地数据。 已有超过50k参与...

回答 1 投票 0

术后冲洗是否可以坚持?

我已阅读有关生命周期事件的文档,以及有关在生命周期事件期间更改或保留新实体的几个问题。调用 EnityManager::flush() 似乎是一个问题...

回答 2 投票 0

Symfony 表单管理 OneToManyToOne 关系(带有额外字段的ManyToMany)

也许你们中的一些人可以帮助我? 我正在努力构建我正在构建的表单。在我的应用程序中,用户可以创建名为“家庭”的群组并邀请其他用户加入该家庭。我想创造...

回答 1 投票 0

如何将实体重新保存为原则 2 中的另一行

假设我有实体 $e。是否有任何通用方法将其存储为另一行,该行将具有相同的实体数据但另一个主键? 为什么我需要这个:我正在实施某种 Tempo...

回答 5 投票 0

Symfony 7 Doctrine EventSubscriber 未使用

尝试注册 Doctrine EventSubscriber 但不起作用。 (交响乐7) 这是订阅者: 尝试注册 Doctrine EventSubscriber 但不起作用。 (symfony 7) 这是订阅者: <?php namespace App\EventSubscriber; use Doctrine\Common\EventSubscriber; use Doctrine\ORM\Events; use Doctrine\Persistence\Event\LifecycleEventArgs; class LogSubscriber implements EventSubscriber { public function getSubscribedEvents() { return [ Events::postPersist, Events::postUpdate, Events::postRemove ]; } public function postPersist(LifecycleEventArgs $args) { dd($args); } public function postUpdate(LifecycleEventArgs $args) { dd($args); } public function postRemove(LifecycleEventArgs $args) { dd($args); } } 和我的 services.yaml # This file is the entry point to configure your own services. # Files in the packages/ subdirectory configure your dependencies. # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: services: # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name App\: resource: '../src/' exclude: - '../src/DependencyInjection/' - '../src/Entity/' - '../src/Kernel.php' # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones App\EventSubscriber\LogSubscriber: tags: - { name: doctrine.orm.event_subscribe, connection: default } 我尝试使用“doctrine.event_subscribe”,但这不起作用。 我真的不明白出了什么问题,提前感谢您的帮助。 正如 @yolenoyer 评论的那样,该界面已被弃用。 为您的监听器添加新的 PHP 8 属性 <?php declare(strict_types=1); namespace App\EventListener; use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; use Doctrine\ORM\Event\PostPersistEventArgs; use Doctrine\ORM\Event\PostRemoveEventArgs; use Doctrine\ORM\Event\PostUpdateEventArgs; use Doctrine\ORM\Event\PrePersistEventArgs; use Doctrine\ORM\Event\PreRemoveEventArgs; use Doctrine\ORM\Events; #[AsDoctrineListener(event: Events::prePersist, priority: 0, connection: 'default')] #[AsDoctrineListener(event: Events::postPersist, priority: 0, connection: 'default')] #[AsDoctrineListener(event: Events::postRemove, priority: 0, connection: 'default')] #[AsDoctrineListener(event: Events::postUpdate, priority: 0, connection: 'default')] #[AsDoctrineListener(event: Events::preRemove, priority: 0, connection: 'default')] class EventListener { public function prePersist(PrePersistEventArgs $event): void { $this->logger->debug('-- PrePersistListener::PREPERSIST --'); } public function postPersist(PostPersistEventArgs $event): void { $this->logger->debug('-- PostPersistListener::POSTPERSIST --'); } public function postRemove(PostRemoveEventArgs $event): void { $this->logger->debug('-- PostRemoveListener::POSTREMOVE --'); } public function postUpdate(PostUpdateEventArgs $event): void { $this->logger->debug('-- PostUpdateListener::POSTUPDATE --'); } /** * You need to listen to preRemove if you use soft delete * from Doctrine extensions, because it prevents postRemove * from being called. */ public function preRemove(PreRemoveEventArgs $event): void { $this->logger->debug('-- PreRemoveListener::PREREMOVE --'); } }

回答 1 投票 0

Doctrine QueryBuilder 删除连接

我正在尝试使用 Doctrine QueryBuilder 来执行以下 SQL 查询: 从product_hole_pattern php中删除php 内连接hole_pattern hp ON php.hole_pattern_id = hp.id 内连接

回答 5 投票 0

Doctrine2 - 没有关系的子查询连接

好的,这就是问题所在。 我有一个名为 HelpDocuments 的实体和一个名为 LogEntry 的实体。 用户可以关闭帮助文档。发生这种情况时,我创建一个具有以下属性的 LogEntry...

回答 1 投票 0

如何选择同时具有多对多关系中的项目的行

假设我有“新闻”实体,它具有多对多“标签”关系 班级动态 { /** * @ORM\ManyToMany(targetEntity="App\Domain\Entity\Vocabulary\Tag") ...

回答 1 投票 0

教义wrapInTransaction 不持久

在PHP8.1上使用Doctrine v2.12.2和MySQL5.7.38数据库,尝试使用下面定义的setValue函数内部的wrapInTransaction方法来持久化数据实体;我的理解是...

回答 1 投票 0

使用 createQuery 的 Doctrine 查询返回结果数

$q = $this->_em->createQuery("从 app\models\Quest 中选择 左连接 s.que c WHERE s.type = '$sub' ...

回答 2 投票 0

Symfony Doctrine 使用新操作符水合结果

是否可以使用 Doctrine 自动构建一个以子 DTO 作为属性的结果数组? 例如,假设只能有一个孩子,我有以下

回答 1 投票 0

Symfony2/Doctrine2 从 querybuilder 对象获取连接实体

给定两个一对多关联的学说实体(个人和公司),以及一个看起来像这样的存储库 命名空间 TestBundle\Entity\Repository; 使用 Doctrine\ORM\EntityRepository;

回答 2 投票 0

插入前检查列是否可为空?

TL;DR:我可以在持久化期间或之前检查字段是否可为空吗? 我目前正在尝试找到一种顺利的方法来实现“如果足够完整则插入条目”表单。 这个简单...

回答 1 投票 0

Symfony 7 身份验证问题:“令牌无效或被篡改:HMAC 验证失败(401 未经授权)”

我在尝试在 Symfony 中实现登录过程的自定义身份验证时遇到身份验证问题。尽管配置了 security.yml 文件以允许访问而无需

回答 1 投票 0

为什么我的多对多关系在 Doctrine 和 Symfony 中不起作用?

我有一个多对多关系定义如下: 两个相关表: 创建表“讲道”( `homilyID` int NOT NULL AUTO_INCRMENT, ‘讲道’文本不为空, 主键(`homilyID`)...

回答 1 投票 0

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