doctrine-orm

Symfony Doctrine update query fail

浪尽此生 提交于 2021-01-28 05:33:35
问题 My code is: $query = $em->createQuery("UPDATE AppBundle:Project u SET u.name=1, u.key=?2, u.leader=?3 WHERE u.id = ?4"); $query->setParameter(1, $project->name); $query->setParameter(2, $project->key); $query->setParameter(3, $project->lead->name); $query->setParameter(4, $project->id); $result = $query->getResult(); Now when I run it, it gives me a error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your

Symfony2: class 'Doctrine\Common\Collections\ArrayCollection' was not found in the chain configured namespaces

烈酒焚心 提交于 2021-01-28 04:03:38
问题 Error occurs when attempting to persist a one-to-many relationship. In particular, a client may have multiple household members; a given household member is associated with one and only one client. [I am new to Symfony so errors are expected!] Your guidance gratefully accepted. N.B. Alternate controller snippet below yields integrity constraint error by trying to set the client's id in the household table to null. Clients Entity snippet namespace Mana\AdminBundle\Entity; use Doctrine\ORM

Symfony2: class 'Doctrine\Common\Collections\ArrayCollection' was not found in the chain configured namespaces

让人想犯罪 __ 提交于 2021-01-28 03:43:17
问题 Error occurs when attempting to persist a one-to-many relationship. In particular, a client may have multiple household members; a given household member is associated with one and only one client. [I am new to Symfony so errors are expected!] Your guidance gratefully accepted. N.B. Alternate controller snippet below yields integrity constraint error by trying to set the client's id in the household table to null. Clients Entity snippet namespace Mana\AdminBundle\Entity; use Doctrine\ORM

DQL query returns: StateFieldPathExpression or SingleValuedAssociationField expected

跟風遠走 提交于 2021-01-28 02:51:00
问题 I have the following DQL query: public function findByIdJoinedToCodeExample($pageId) { $query = $this->getEntityManager() ->createQuery(' SELECT c FROM acmeStyleGuideBundle:codeExample c JOIN c.PageContent p WHERE p.codeExample = :cex' ) ->setParameter('cex', $pageId); try { return $query->getResult(); } catch (\Doctrine\ORM\NoResultException $e) { return null; } } It is attempting to retreive data from an entity called codeExample which has a ManyToOne relationship with an entity called

DQL query returns: StateFieldPathExpression or SingleValuedAssociationField expected

主宰稳场 提交于 2021-01-27 23:50:00
问题 I have the following DQL query: public function findByIdJoinedToCodeExample($pageId) { $query = $this->getEntityManager() ->createQuery(' SELECT c FROM acmeStyleGuideBundle:codeExample c JOIN c.PageContent p WHERE p.codeExample = :cex' ) ->setParameter('cex', $pageId); try { return $query->getResult(); } catch (\Doctrine\ORM\NoResultException $e) { return null; } } It is attempting to retreive data from an entity called codeExample which has a ManyToOne relationship with an entity called

Doctrine can't generate a schema when using single table inheritance?

≯℡__Kan透↙ 提交于 2021-01-27 17:27:52
问题 An interesting problem. I'm building an application using Symfony 2 and I'm trying to get Doctrine to auto-generate my schema from my entity classes. I have two entity classes, Invoice and CreditNote . CreditNote extends Invoice . They look like this - Invoice.php - namespace My\Bundle\BillingBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="invoice") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="discriminator", type="string") *

Doctrine return null in place of EntityNotFoundException

落花浮王杯 提交于 2021-01-27 14:13:55
问题 I have broken FKs in my database and if I load an entity and ask for a related entity Doctrine will throw \Doctrine\ORM\EntityNotFoundException . For the entity in question, I would prefer that where the FK is broken it would return NULL rather than throw an exception. This is because its within a Twig template that the exception occurs and I would prefer Twig to not have to have to handle the exception in this case. The following is an example configuration. <?xml version="1.0" encoding="utf

How to fix “This repository can be attached only to ORM sortable listener” error in Gedmo sortable?

空扰寡人 提交于 2021-01-27 05:24:17
问题 When usieing StofDoctrineExtensions (which is a Symfony2 port of Gedmo Doctrine Extensions) Sortable behaviour I kept on getting this error: This repository can be attached only to ORM sortable listener Since I could not easily find the answer in official docs I'm leaving an answer here for future reference. 回答1: You need to enable any listeners you are using. In this case, Sortable. stof_doctrine_extensions: default_locale: en_US orm: default: sortable: true For Symfony 4, add this

How to fix “This repository can be attached only to ORM sortable listener” error in Gedmo sortable?

一个人想着一个人 提交于 2021-01-27 05:23:31
问题 When usieing StofDoctrineExtensions (which is a Symfony2 port of Gedmo Doctrine Extensions) Sortable behaviour I kept on getting this error: This repository can be attached only to ORM sortable listener Since I could not easily find the answer in official docs I'm leaving an answer here for future reference. 回答1: You need to enable any listeners you are using. In this case, Sortable. stof_doctrine_extensions: default_locale: en_US orm: default: sortable: true For Symfony 4, add this

“Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory::__construct() must be an instance…”

我怕爱的太早我们不能终老 提交于 2021-01-20 08:53:45
问题 While attempting to install Api-Platform (or run composer update on an existing Api-Platform installation, I get an error like this: Uncaught Error: Argument 1 passed to ApiPlatform\Core\Bridge\Doctrine\Orm\Metadata\Property\DoctrineOrmPropertyMetadataFactory::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given, called in App_KernelDevDebugContainer.php on line 1530 ["exception" => TypeError { …}] What can