doctrine-orm

How do I use a complex criteria inside a doctrine 2 entity's repository?

懵懂的女人 提交于 2020-01-09 08:55:47
问题 Lets say I have a table that holds information about festivals. Each festival has a start and end date. I want to select all the festivals that are live (that happen) on a given date. Meaning, I want to select all the festivals that their start date is before or on a given date, and that their end date is after or on a the same given date. So I went on to the repository class of the festival entity, and created a method to do just that. But the criteria argument "findBy" expects is an array,

Auto quote reserved words with Doctrine 2

感情迁移 提交于 2020-01-09 04:52:07
问题 Is there a way to auto quote reserved words with Doctrine 2 when using $entityManager->find('entity', id) ? When using the query builder this can be done but there should be a global configuration setting that does this? I don't want to have to specify it in the annotations for the reserved words. 回答1: This was an issue I raised a while back with the Doctrine team. https://github.com/doctrine/doctrine2/issues/2409 The ticket was closed with the comment: You have to manually escape characters

How can i do update table doctrine

筅森魡賤 提交于 2020-01-07 09:45:50
问题 I have this script for inserting the data: echo "Update "; $department = new Department(); $department->setNamedepartment($data ['nameDepartment']); $department->setCodedepartment($data ['codeDepartment']); $department->setIdfkgeographicalarea($data ['idFkGeographicalArea']); $entityManager->persist($department); $entityManager->flush(); how can I update my $department entity with only this call: update($data,$id) ? 回答1: function update ($data, $id) use ($entityManager) { $departament =

Calling an entity's setter for updating its column from a controller of another entity

烂漫一生 提交于 2020-01-07 09:05:11
问题 I need to update the Client table's budget column after inserting a new Budget into the database, but it doesn't. This is how I am doing inside of BudgetController::addAction() : if ($form->isValid()) { $manager->persist($form->getData()); $manager->flush(); $Client = $manager->getReference('PanelBundle:Client', $form['client_id']->getData()->getId()); $Client->setBudget($manager->getRepository('PanelBundle:Budget')->getLastId()); $this->addFlash('success', 'Novo orçamento adicionado');

FOSUserBundle generate:entities does not work, Access level of fields too high

∥☆過路亽.° 提交于 2020-01-07 02:01:07
问题 I have a problem with FOSUserBundle after I configured DoctrineExtensions, with StofDoctrineExtensionsBundle. First of all, to install DoctrineExtensions I had to remove "auto_mapping: true" segment from app/config/config.yml file. I found that if auto_mapping is not active I have to include FOSUserBundle: ~ in default:mappings segment. But, when I try php app/console doctrine:schema:update --force or php app/console doctrine:generate:entities FOS I get: PHP Deprecated: Comments starting with

Symfony2 and Doctrine Query with Distance (Lonigtude and Latitude) and large relationships - Weird result count?

核能气质少年 提交于 2020-01-07 00:40:07
问题 I have a large relationship models between many entities. Menu <> MenuSection <> Section <> SectionEntry <> Entry Entry <> EntryTag <> Tag Menu <> MenuLocation <> Location The Location entity got attributes like longitude and latitude to calculate the distance between the user's current position and the "location". I wrote a lil' bit larger doctrine query. YES, there are many relationships (many to many, many to one and so on, but the relation tables (e.g. entry_section) exist to store some

How can I fetch every row where column is not in (array of values) with Doctrine?

戏子无情 提交于 2020-01-06 19:44:08
问题 I'm trying to accomplish something similar to the following SQL, but using the Doctrine API. SELECT * FROM table_name WHERE column_name NOT IN (1, 2, 3); I was thinking of something like this: $entityManager->getRepository($entity)->findBy(array('ID' => array('NOT IN' => array(1, 2, 3)))); ... How far am I? 回答1: You can do this with a DQL: $result = $entityManager->createQuery("SELECT e FROM $entity e WHERE e.ID NOT IN (:ids)") ->setParameter('ids', array(1, 2, 3), \Doctrine\DBAL\Connection:

Symfony + Doctrine + Annotation validation not work in forms

◇◆丶佛笑我妖孽 提交于 2020-01-06 18:12:47
问题 I'm using doctrine annotations in my entities definition to define each variable behavior, i.e.: @ORM\Column(type="string", length=50, nullable=false) If I submit the form leaving the field empty, it pass the validation, but (of corse) I receive an error about the INSERT statement, because he cannot insert NULL value. How this could be possible? 回答1: This is because Symfony does not automatically validate your form input based on Doctrine annotations. Symfony2 ships with a Validator component

Symfony2 and Doctrine: Many-to-many relation using query builder

五迷三道 提交于 2020-01-06 15:11:33
问题 I have 2 entities: User and Archive. The user entity has, among others, two properties: /** * @ORM\OneToMany(targetEntity="My\ApplicationBundle\Entity\Archive", mappedBy="user") **/ protected $archives; /** * @ORM\ManyToMany(targetEntity="My\ApplicationBundle\Entity\Archive", inversedBy="users") * @ORM\JoinTable(name="collection") **/ private $collection; and the Archive entity: /** * @ORM\ManyToOne(targetEntity="My\UserBundle\Entity\User", inversedBy="archives") * @ORM\JoinColumn(name="user

Generate Uuid manually in constructor or via UuidGenerator annotation

不羁的心 提交于 2020-01-06 15:01:52
问题 I am switching to Ramsey\Uuid and don't know what is the intended way to generate the Uuids. Either as shown in the examples with an anntoation: /** * @var UuidInterface * * @ORM\Id * @ORM\Column(type="uuid", unique=true) * @ORM\GeneratedValue(strategy="CUSTOM") * @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator") */ private $id; public function __construct() { } Or manually in the constructor: /** * @var UuidInterface * * @ORM\Id * @ORM\Column(type="uuid", unique=true) */