Symfony 2 entity join or doctrine query join

I was wondering if it was possible to configure a entity to automatically load data from another entity.Ex./** * accountsUsers * * @ORM\Table() * @ORM\Entity */class accountsUsers{ /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ public $id; /** * @var string * * @ORM\Column(name="userid",type="integer") */ public $userid; /** * @var string * * @ORM\Column(name="roleid",type="integer") */ public $roleid; ...Read more

symfony - Symfony2 doctrine association mapping error handling

I get the following error when using php app/console doctrine:schema:update --force.[Doctrine\DBAL\DBALException] An exception occurred while executing 'ALTER TABLE profiles ADD CONSTRAINT FK_8B30853036802B0F FOREIGN KEY (participantid) REFERENCES participants (id )': SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`smartplan_dev`.`#sql-518_...Read more

symfony - How to use findById in indexAction side by findAll()?

im trying to edit my indexAction function, i want to findByOne for userpublic function indexAction() { $em = $this->getDoctrine()->getManager(); if ($this->isGranted('ROLE_ADMIN')) { $leaveRequests = $em->getRepository('AppBundle:LeaveRequest')->findAll(); } else { $leaveRequests = $em->getRepository('AppBundle:LeaveRequest')->findOneBy(['id‌​' => $id]); } return $this->render('leaverequest/index.html.twig', array( 'leaveRequests' => $leaveRequests, ));}And I get the following...Read more

Symfony Base64_encode on pdf in response

I want to base64_encode a pdf file before returning it to the client.Here is what I do$response = $event->getResponse();$response->headers->remove('Content-Disposition');$response->setContent( $response->headers->get('Content-Type') . ';base64,' . base64_encode($response->getContent()));$response->headers->set('Content-Type', 'text/plain');The pdf that I get in a browser when I put data:<base64_encoded_string> doesn't have any value, but the whole skeleton/css is ok.If I do $response = $event->getRes...Read more

symfony - Doctrine onFlush - catch entity changed fields

I need to store all changed field in logs when user change something in Product Entity.I have event subscriber which works fine. I have two methods. Onflush and postFlush.In onFlush method I have simply this:public function onFlush(OnFlushEventArgs $args): void{ $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); foreach ($uow->getScheduledEntityUpdates() as $key => $entity) { if ($entity instanceof Product) { $this->entitiesToProcess[] = $entity; } } /** * @var PersistentColl...Read more

symfony - How to create a good hypermedia format using JMSSerializerBundle?

Lets say I want to create an XML-response that will looks something like the following:<?xml version="1.0" encoding="utf‐8"?><product xmlns="urn:com.acme.prods" xmlns:atom=""> <id>1234</id> <name>Red Stapler</name> <price currency="EUR">3.14</price> <atom:link rel="payment" type="application/" href="" /></product>Given an domain model that looks something like the following:<?php// Prod...Read more

Symfony getData event subscriber is null

I know, this question has been asked already a couple of times but there hasn't been an answer that actually helped me solving my problem.I've gut three EventSubscribers for three Dropdowns who are dependent on each other.So in my FormType I say: public function buildForm(FormBuilderInterface $builder, array $options){ // solution showmethecode $pathToAgencies = 'agencies'; // $builder ->addEventSubscriber(new AddChannel1Subscriber($pathToAgencies)) ->addEventSubscriber(new AddChannel3Subscriber($pathToAgencies)) ->addEve...Read more

doctrine - Symfony assert type vs One-to-One mapping

In the Symfony documentation about Embed forms, I just read this : class Task{ /** * @Assert\Type(type="AppBundle\Entity\Category") * @Assert\Valid() */ protected $category; // ...}They later say that The Category instance is accessible naturally via $task->getCategory() and can be persisted to the database or used however you need.How is that different from a Many-To-One mapping ? (many tasks for one category of course)...Read more

doctrine orm - Could not resolve type of column Symfony

I want to achieve a join between my product entity and my provider entity, only, all seems ok but it does not work ..My mistake : Could not resolve type of column "id" of class "AppBundle\Entity\Colombus\Provider"Could not resolve type of column "id" of class "AppBundle \ Entity \ Columbus \ Provider"Here is the mapping of the Product entity:<?phpnamespace AppBundle\Entity\Colombus;use Doctrine\ORM\Mapping as ORM;/** * Product * * @ORM\Table(name="product") * @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository") */class Produ...Read more

symfony - Can I organize Doctrine entities or their mapping files into subfolders?

I have tried this directory structure for my mapping files:/config/doctrine/Place.orm.yml/config/doctrine/Place/Type.orm.yml/config/doctrine/Place/Price.orm.ymlAnd have pointed to the corresponding Entity in my mapping file like this:Project\TestBundle\Entity\Place\Type: type: entity table: place_type id: id: type: integer generator: { strategy:AUTO } fields: name: type: string length: 255But this returns an error. The system can't seem to detect the mapping file for Entity....Read more

doctrine orm - @ORM\Id does not make an identifier for an entity in symfony

I hava a class City which consists of a number of traits./** * @ORM\Entity * @ORM\Table(name="City") * @SoftDeleteable(fieldName="deletedAt") */class City{ use IdentifiableEntity; use TimestampableEntity; }I have a trait IdentifiableEntitytrait IdentifiableEntity{ /** * @var integer * @ORM\Column(name="id", type="integer", options={"unsigned":true}) * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; //setter getter}the problem occurs when I execute bin/console doctrine:migrations:diff I get ...Read more

How to configure Doctrine to use yaml mapping on Symfony 4

I'm new to Symfony 4I use Doctrine an I want to use yaml entity mapping.So i configured the file doctrine.yaml and change type:annotation to type:yml.And when I tried php bin/console make:entity, there is no yaml mapping file generated linked to this entitythis is my doctrine.yaml file:parameters: # Adds a fallback DATABASE_URL if the env var is not set. # This allows you to run cache:warmup even if your # environment variables are not available yet. # You should not need to change this value. env(DATABASE_URL): ''doctrine: db...Read more

Double mapped relation in symfony? It is possible?

I have no ideal how to double map entity in symfony.I have tableMatches________id u_id1 : reference to useru_id2 : reference to userstatus: enum Now i don't want to create double records per one match.I want to load user matches where u_id1 = user_id or u_id2 = user_id.So.. i want make my method in user object inteligent usefully . eg $user->getMatches(); what returns matches where first or second u_id have current user id.Any idea?...Read more

symfony - Reference ORM (Entity) from ODM (Document, MongoDB) with ManyToMany relationship

I am trying to blend ODM (MongoDB) and ORM in my Symfony 2.6 with a reference to the Documentation "Blending ORM and MongoDB ODM"I have two entities, User and Category. Also I have one Document Product.It's clear when blending ODM and ORM, it can be solved easily with OneToMany or ManyToOne case - on one side we define ReferenceOne link + both field specifing identifier="fieldId" and fieldId itself, on another side we define ReferenceMany).My challenge is getting $product->categories populated with relation ManyToMany. So far, $product->u...Read more

Symfony 2.8 how to default select value in Dropdown using Propel

I have created one dropdown for employee Role. In edit mode how to select user selected role.$builder->add('homePageId', \Propel\Bundle\PropelBundle\Form\Type\ModelType::class , array( 'class' => 'Admin\HomePageBundle\Model\HomePage', 'required' => true, 'multiple' => false, 'expanded' => false, 'query' => HomePageQuery::create()->orderByName(), 'property' => 'name', 'preferred_choices' => array('5') ));I have added ...Read more