doctrine-orm

Load Container and EntityManager within a fixture in Symfony2

北城以北 提交于 2020-01-02 22:02:14
问题 I have two fixtures, one LoadSport.php and one LoadCategory.php in my Symfony project. Every instance of sport has a private 'category' attribute which is an instance of Category. I am trying to retrieve the categories I already in my database and load them in the Sports fixture (I chose some sports). I followed the official using container within fixtures (http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html#using-the-container-in-the-fixtures) as suggested in another

Set value for the primay key with strategy set to NONE

巧了我就是萌 提交于 2020-01-02 14:39:33
问题 I have an Entity class that looks like this: <?php namespace Entities; /** @Entity @Table(name="User") */ class User { /** * @Id * @Column(type="string", length=12) */ private $no; Based on Doctrine 2 Identifier Generation Strategy section: NONE: Tells Doctrine that the identifiers are assigned (and thus generated) by your code. The assignment must take place before a new entity is passed to EntityManager#persist. NONE is the same as leaving off the @GeneratedValue entirely. That means, I

How do I persist Images with Doctrine

Deadly 提交于 2020-01-02 12:05:14
问题 I want to persist an Image in my Article Entity. Is this possible with Doctrine2? How do i do this? Best Regards, bodo 回答1: This is pretty simple using the ODM setup with the @File type. For a ORM entity, I would look at creating a column like so. NOTE: Use this link to add the blob type to Doctrine2 How add BLOB type in Doctrine 2 using Symfony 2 /** @ORM\Column(type="blob") */ protected $imageData; /** @ORM\Column(type="string") */ protected $imageType; /** @ORM\Column(type="int") */

Doctrine 2.0 Bootstrap?

我是研究僧i 提交于 2020-01-02 07:39:52
问题 Ok, so I've got the Doctrine.php file in a folder hierarchy like so: \ includes\ Setup.php Doctrine\ Common\ DBAL\ ORM\ Symfony\ Doctrine.php My setup.php has the following: $rootPath = $_SERVER['DOCUMENT_ROOT']; $includePath = getcwd() . "\includes"; ini_set('include_path', '.'.PATH_SEPARATOR.$rootPath.PATH_SEPARATOR.$includePath); require_once 'includes\Doctrine\Doctrine.php'; My Doctrine.php is: <?php /* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND

symfony 2.4 can't get the doctrine channel in prod environment

不羁的心 提交于 2020-01-02 07:22:13
问题 I can't manage to get a log of the doctrine channel in my prod environment. I'm using symfony/symfony v2.4.6 symfony/monolog-bundle v2.6.0 doctrine/common v2.4.2 Here is my monolog config in config_prod.yml : monolog: handlers: doctrine: bubble: false action_level: DEBUG type: stream path: "%kernel.logs_dir%/%kernel.environment%_doctrine.log" channels: doctrine security: bubble: false action_level: DEBUG type: stream path: "%kernel.logs_dir%/%kernel.environment%_security.log" channels:

Cloning object after getting data from a form in Symfony2

馋奶兔 提交于 2020-01-02 07:21:11
问题 I'm sure I'm missing something very basic here. I have a form, and when the user updates the fields of the form I don't want to update the underlying entity but want to create a new entity with the new values. To clone Doctrine entities I followed the indication here. So my code is (let's say I want to clone the object with id=3: $id = 3; $storedBI = $this->getDoctrine() ->getRepository('AppBundle:BenefitItem') ->find($id); $form = $this->createForm(new BenefitItemFormType(), $storedBI);

Symfony 3.0.4 Circular reference detected during serialization with FOSRestBundle

守給你的承諾、 提交于 2020-01-02 06:10:53
问题 I'm using FOSRestBundle in a Symfony project. When it I try to handle a view, it fails during the serialization of my data with the Symfony serializer as well as with the JMSSerializer. This is the method rendering the response: DefaultController.php $em = $this->getDoctrine()->getManager('magellan'); $qb = $em->createQueryBuilder(); $query = $qb->select('h') ->from('DataBundle:Holding', 'h') ->where($qb->expr()->eq('h.id', ':holding_id')) ->setParameter('holding_id', $holding_id) ->getQuery(

Doctrine's entity manager crashes and stays down

痴心易碎 提交于 2020-01-02 04:16:06
问题 So, when I run tests on my ZF/Doctrine application, some tests happen to break the Doctrine Entity Manager, and all the sequential tests fail due to EM being closed. I set the EM up in my tests/bootstrap.php: $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap(); (...) $bootstrap = $application->getBootstrap(); $em = $bootstrap->getResource('doctrinemanager'); Then I set it inside the test setUp() function ($this->

Doctrine generating query with wrong table alias

帅比萌擦擦* 提交于 2020-01-02 04:12:11
问题 I'm trying to do a simple ->find() using doctrine/orm 2.5.1. The query is quite simple: $this->get('order_repository')->find(10); But this is generating a complex query: SELECT s0_.number AS number_0, s0_.state AS state_1, s0_.completed_at AS completed_at_2, s0_.items_total AS items_total_3, s0_.adjustments_total AS adjustments_total_4, s0_.total AS total_5, s0_.created_at AS created_at_6, s0_.updated_at AS updated_at_7, s0_.deleted_at AS deleted_at_8, s0_.id AS id_9, s0_.expires_at AS

Cannot select entity through identification variables without choosing at least one root entity alias

北城以北 提交于 2020-01-02 04:10:31
问题 Ads entity is described by geographic information: Country> Region>County . The Ads entity is only linked with County . Consequently, retrieving Ads by countries will require us joining entities twice. My goal is counting the number of Ads for a given country. For that, I tried this DQL query but without success: public function getMotorsAdsCountByCountry($slug){ $qb = $this->_em->createQueryBuilder() ->select("m.id, COUNT(m.id) AS cnt") ->from("MinnAdsBundle:MotorsAds", "m") ->join("m.county