Doctrine orm Group By aliasin Doctrine. Bug or Feature?

I'd like to highlight an issue that was previously discussed here, or seems to have been resolved a long time ago, but the problem still persists. Actually, it's impossible to use an alias in a group by clause. Like the mentioned topic, I also get an "Error: '...' does not point to a Class". However, aliases, in the order by clause, work perfectly. For instance, this DQL request works: SELECT, DATE(j.start_at) AS date FROM jobs j ORDER BY date But this doesn't (whereas it works in SQ

Doctrine orm Doctrine 2 - NativQuery with UNION

I want hydrate a UNION result to an entity. My problem is, at a UNION I do not have alias at the result? public function getDialogHistoryQuery($addr, $page = 1, $count = 10) { $count = (int) abs($count); $page = max((int) $page, 1); $limitStart = (int)($page - 1) * $count; $sql = "(SELECT 'in' AS direction,, ib.from_addr AS addr, ib.receive_time AS time, ib.message FROM smsd_inbound AS ib WHERE ib.from_ad

Doctrine orm DQL - Selecting multiple fields, but fetching only one - hiding fields from resultset

Given following DQL query: SELECT p, (p.views * 0.1) + (p.likes * 0.9) as ratingPhoto FROM AppBundle:Photo p ORDER BY ratingPhoto DESC My resultset will look like following: array (size=14) 0 => array (size=2) 0 => object(Photo) 'ratingPhoto' => string '1.42' (length=4) 1 => array (size=2) 0 => object(Photo) 'ratingPhoto' => string '1.31' (length=4) ... Is there any DQL functionality so that I will only retrieve th

Doctrine orm Zend 2 Doctrine 2 Gedmo Translatable

I am trying to use the Gedmo translatable extension for Doctrine 2 in a Zend Framework 2 application. I have it setup like this: 'doctrine' => array( 'eventmanager' => array( 'orm_default' => array( 'subscribers' => array( 'Gedmo\Translatable\TranslatableListener' ) ) ), 'driver' => array( 'application_entities' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',

Doctrine orm How to retrieve only one row for Doctrine2 entity?

I am working with the entities Price and Product. Every Product has several Prices. With the getter Product->getPrices i can retrieve all Prices. Every Price has a field insertedAt which stores a DateTime object. My Problem I want to retrieve only the latest Price for a Product but i dont know how to do this. Solution (by Maerlyn) (UPDATE) My next problem I am using not only then insertedAt-field but also a condition and a source-field. So i

Doctrine orm merge in doctrine 2 not working giving error

I am trying to update a row in a table. I am using doctrine 2 ORM. I am trying to update a row using merge(), which is said can be used to update a row. But it gives a error saying Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry I am new to doctrine 2. please suggest what can i do?

Doctrine orm Doctrine many to many using join table and ArrayCollection::map

I have entities "User" and "Agency". There is a many-to-many relationship between these, but since there are data on the joins between the two, both entities have a OneToMany relationship to a join entity. So far so good. However, I have a possibly slightly unusual use case in that my joins need to persist after a User is deleted. This is because some other data about the deleted user stays on elsewhere, and it's necessary to know about the Agency entities that a User was associated with. I

Doctrine orm Doctrine: Hijack a delete operation and make record invalid instead

In order to avoid the Slowly Changing Dimension problem (in short: I want to keep my order data even if a user gets deleted from the system), I thought about hijacking the delete event and instead setting an invalid flag on the record. I know of the softdeletable filter from StofDoctrineExtensionsBundle but I'm unsure if this will cascade to child objects. Is this a common/good practice/idea and do this with the following lifecycle callback?: / /** * @ORM\PreRemove */ public function mak

Doctrine orm ManyToOne from multiple entities into one

I have 3 entities: client company contact client entity can have multiple contact entities, also company can have multiple contact entities. Contact entity looks like this: class ContactDetail { use Timestampable; use Bleamable; CONST TYPE_EMAIL = 'EMAIL'; CONST TYPE_PHONE = 'PHONE'; CONST TYPE_FAX = 'FAX'; CONST TYPE_MOBILE = 'MOBILE'; /** * @ORM\Id * @ORM\Column(type="integer", options={"unsigned"=true}) * @ORM\GeneratedValue(strategy="AUTO")

Doctrine orm How to get query based on Repository / Criteria in Doctrine?

How in Doctrine may I get a query based on Criteria? I have the following Doctrine Criteria set: $criteria = Criteria::create(); $criteria->where(Criteria::expr()->eq("versionFinale", true)) ->andWhere(Criteria::expr()->eq("versionSoftDeleted", false)) ->andWhere(Criteria::expr()->eq("versionStatus", "PUBLISHED")); Normally I would use the following code to get results: $repo->matching($criteria) However, as I want to use KNP Paginator I need a query. I coul

Doctrine orm Issue with persisting specific relation with Doctrine2 ODM

I am using Doctrine 2 MongoDB ODM, all working fine except 1 specific relation. What's obscure is that I have seemingly identical relations in the project and they all work just fine namespace Project\Entities\World; // same NS as class, but this is after // splitting functionality from Entity to MappedSuperclass, didn't work either /** * @ReferenceOne(targetDocument="Project\Entities\World") * @var IWorld */ protected $world; used in Project\Entities\PlayerCharacter (extends Project\Enti

Doctrine orm doctrine2 slugable and datafixtures

I'm trying to make a Field of a Object slugable. Model looks like: namespace myBundle\Bundles\BlogBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Gedmo\Mapping\Annotation as Gedmo; /** * myBundle\Bundles\BlogBundle\Entity\Category * * @ORM\Table() * @ORM\Entity */ class Category { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */

Doctrine orm DoctrineModule "reflection exception" in ZF2

Working with the Zend Framework 2 application skeleton, I have installed DoctrineModule and DoctrineORMModule according to the instructions. I am getting this error when trying to execute the doctrine.php command line tool. (FYI I do not get the error if I uninstall DoctrineORMModule) Fatal error: Uncaught exception 'ReflectionException' with message 'Class Doctrine\DBAL\Connection does not exist'... Any ideas?

Doctrine orm YamlDriver for Doctrine2 in Zend2

I'm using the DoctrineORMModule to integrate Doctrine2 with Zend2. Everything works just fine when I'm using the AnnotationDriver as described in various examples. However, I cannot get the YamlDriver to work. In my module.config.php I tried: 'doctrine' => array( 'driver' => array( 'ApplicationDriver' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'cache' => 'array', 'paths' => array(__DIR__ . '/../src/Appli

Doctrine orm Doctrine2 Many to Many fetch rows issue

I have a problem passing a value to Doctrine2 QueryBuilder in Symfony2. I have two Entyties joined in unidirectional ManyToMany relationship: Articles and Tags, and it works fine, but when I try to pass a value to the qb parameter it reads Error espetcted Literal got 'ORDER' or get nothing (but records exists). The code: $em=$this->getDoctrine()->getEntityManager()->getRepository('Bundle:Articles'); $qb = $em->createQueryBuilder('l') ->select('l,t') ->leftJoin(

Doctrine orm doctrine2 Jointable Annotation

I bet there is a really easy solution to this, but I just can't figure it out. If you need any extra info, please point it out. I have 3 tables: User Job - ManyToMany User JobReport - ManyToMany Job , ManyToMany User Both user and job exists in db. So the php calls are: $report = new JobReportEntity(); //get user $userWhoReports = $this->getEntityManager()->getRepository("Entity\User")->find(1); //get job $queryBuilder = $this->em->createQueryBuilder() ->select(array

Doctrine orm Doctrine2 entity and Zf2 JsonModel()

I see a few ways to give Zend\View\Model\ViewModel::setVariables an array: Implement in entity toArray() and make JsonModel($entity->toArray()) Use DoctrineModule\Stdlib\Hydrator\DoctrineObject and $hydrator->extract($entity); Implement Iterator for entity and extends from it And the question is, how can i implement iterator for Doctrine2 entity, and is it a good idea or maybe someone know a better way?

Doctrine orm Doctrine 2 Order By ASC and Null values in last

I am trying to fetch result which and I need to sort in ascending order. But some values would be null/empty, I need the to be in last while sorting starts from 0 1 2 and then null value. I tried SortableNullsWalker but it did not help. The value I am sorting is not column, its a multiplication of two values which is being sorted, thats why I think SortableNullsWalker did not work. Any help please $dql = 'SELECT (column1 * column2) as distance FROM table) ORDER BY distance AS

Doctrine orm Load entity that has been already loaded as a partial association

I have encountered a strange bug related to loading an entity that is already in identity map as a partial. Given I have following entity definition: /** @ORM\Entity */ class Test { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** @ORM\Column(type="string") */ private $name; /** @ORM\Column(type="datetime") */ private $created; /** * @ORM\ManyToMany(targetEntity="Test") */ private $related;

Doctrine orm How to create foreign key constraint without relationship in Doctrine

I have the following 2 tables: +-------+ +------------------------------+ | users | | blocked_users | +-------+ +------------------------------+ | id | | id, user_id, blocked_user_id | +-------+ +------------------------------+ My User class has the following relationship defined: /** * Users the instance user has blocked. * * @ORM\OneToMany( * targetEntity="BlockedUser", * mappedBy="blocker", * fetch="EXTRA_LAZY", * cascade={"persist", "rem

Doctrine orm Symfony 2.8 : DQL query to display an arraycollection

I'm a beginner on Symfony 2 and I have a problem with a DQL query : I'm trying to display a property that is an ArrayCollection. Here's my case : Two classes joined together with a "ManyToOne" and "OneToMany" DishGrade.php : /** * @var Dish $dish * * @ORM\ManyToOne(targetEntity="Dish", inversedBy="grades", cascade={"persist", "remove", "merge"}) * @ORM\JoinColumn(name="dish_id", referencedColumnName="id", nullable=false) * */ private $dish; Dish.php : /** * @var \Doctrine\Common\Collect

Doctrine orm Doctrine: Mapping working on Windows but not on Linux

I'm working on building a Zend Framework 2 website using Doctrine2. I was developing on Windows and everything works but I have uploaded my code to a Linux environment and this error has appeared: The target-entity LeuerOneYear\Entity\UserLeagueRole cannot be found in 'User\Entity\User#leagueRoles'. These are my entities: <?php namespace User\Entity; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; use LeuerOneYear\Entity\UserLeagueRole; use Doctrine\Common\Col

Doctrine orm Symfony form, One-to-one relationship, one side can be null

I have a MainConfig entity that has One-to-one relationship with LedConfig entity. LedConfig can be null. <?php namespace ... use Doctrine\ORM\Mapping as ORM; ... /** * @ORM\Entity */ class MainConfig { ... /** * @ORM\OneToOne(targetEntity="...\LedConfig", cascade={"all"}) * @ORM\JoinColumn(name="led_config_id", referencedColumnName="id", nullable=true, unique = true) */ private $ledConfig = null; ... } <?php namespace ... use Doctrine\ORM\Mapp

Doctrine orm How to setup Class Table Inheritance to tables with different ID-columns' names in Doctrine 2?

I have a table person with id as identifier column and a tables student with person_id as PRIMARY KEY. The column student.person_id references (FOREIGN KEY) the There are accordingly three classes: An abstract class Person with a member id and its sub-classe Student without any "identifying property". I'm trying to define the Class Table Inheritance for this structure: Person use Doctrine\ORM\Mapping as ORM; /** * Parent * * @ORM\Table( * name="person" * ), * @ORM\Entity

Doctrine orm How do I use custom-operators in Doctrine DQL?

I am trying to use PostGIS functions in my queries. I am using jsor/doctrine-postgis package to add relevant functionality to Doctrine. I am not exactly sure if I have configured it incorrectly or if I am doing something wrong. For example: ->where('ST_Intersects(st.coords,ST_MakeEnvelope(-1,-1,1,1,4326))') However this does not work because syntax checker wants a comparison operator. I get the following error: Error: Expected =, <, <=, <>, >, >=, !=, got end of string I ma

Doctrine orm Script cache:clear returned with error code 255 Fatal error: Uncaught Error: Class 'Doctrine\Bundle\DoctrineCacheBundle\DoctrineC

I have a Symfony project that works very well locally but when I put it on the server and I make the command composer install --prefer-dist --no-interaction --no-dev --optimize-autoloader I have every time this error [c1131570c@web44 falah]$ rm -rf vendor && composer install --prefer-dist --no-interaction --no-dev --optimize-autoloader Loading composer repositories with package information Installing dependencies from lock file Package operations: 78 installs, 0 updates, 0 removals -

Doctrine orm Doctrine join filter

I know conditional filters aren't yet available for queries (as per "26.1.4. Applying Filter Rules to any Query" in the Known Limitations section of the Doctrine2 manual) , so I wanted to ask the experts what their preferred solution to the following problem is: My site has product objects that each have many reviews. The reviews have a status field. I don't want to unnecessarily pull in reviews that haven't been approved during the automatic association that Doctrine2 does so wonderfully. M

Doctrine orm Autoload issue in using Doctrine2

cli-config.php <?php require_once 'Doctrine/Common/ClassLoader.php'; $path = dirname(dirname(dirname(__FILE__))); $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__); $classLoader->register(); $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache); $config->setProxyDir(__DIR__ . '/Proxies'); $config->set

Doctrine orm Doctrine2: how to solve left join not being generated

consider these two entities: /** @Entity */ class String { /** @Id @Column(type="integer") * @GeneratedValue */ public $id; /** @Column(length=255) */ public $name; /** * @OneToMany(targetEntity="StringTranslation", mappedBy="owner") */ public $translations; } /** @Entity */ class StringTranslation { /** @Id @Column(type="integer") * @GeneratedValue */ public $id; /* @ManyToOne(targetEntity="String", inversedBy="translations")

Doctrine orm search form using Zend Form with validators and inputFIlters

Is there an example to see how one can implement a search form using Zend Forms in Zend Framework2. I needed a search form for every category and every category has different columns in the database which needs to be searched. Let me say I have a Country category, under this there are many elements which can be searched like country name, states belonging to the county, language spoken in the country and so on. So when a user types either a state or country or language I need to display all

Doctrine orm Query Builder, Like

I have problem with Like in Query Builder: I have SyntaxError: [Syntax Error] line 0, col 243: Error: Expected '.' or '(', got 'type' QueryException: SELECT z as task, GROUP_CONCAT(DISTINCT o.tahoObject) as type FROM Cloud\CrmBundle\Entity\Tasks z LEFT JOIN z.taskOwner u LEFT JOIN z.taskTasksHasObject o WHERE z.taskDone = :ztaskDone AND u.userFirstnameLastname = :uuserFirstnameLastname AND type LIKE :type GROUP BY z.taskId ORDER BY z.taskDate desc Im adding like to the Query Builder like

Doctrine orm Saving common data for fixtures in Doctrine

What are the best-practice ways to keep the common data for the fixtures? Something like users. One entity contain id, another entity firstname and lastname, third entity another data related with user. Then number of users is growing up, number of entities and data in entities growing up too and voila - for adding user in fixtures i edit +100500 files. Is exist some common way except one static class with all related data?

Doctrine orm Controller Cleaning. Doctrine in Model

I want to make my controller thin and to separate business-logic from other operations. For example I have an action: public function indexAction() { $languages = $this ->getEntityManager() ->getRepository('\ApanelLanguage\Entity\LanguageCommon') ->getLanguagesList(); $viewModel = new ViewModel(['languages' => $languages]); return $viewModel; } but I want to get action like this: public function indexAction() { $mo

Doctrine orm PHPUnit force me to mock entity?

Let's take in account this scenario public class FooManager() { //somewhere in my manager class code public function merge(Foo $a, Foo $b, $id) { if ($a->getId() == $id) { //!! PAY ATTENTION !! } //and so on } } I've read pretty much everywhere that mock an entity isn't a good practice but I'm wondering about that particular piece of code. If I can't assign an Id to a real entity object (as, for example, it is auto-generated by doctrine), how can I tes

Doctrine orm Convert this SQL to Doctrine Query Language (DQL)

I got following SQL query SELECT a.* FROM payment_schedule a, ( SELECT loan_application_id, MAX(due_date) max_date FROM payment_schedule WHERE payment_type_id <> 3 GROUP BY 1 ) AS b WHERE a.loan_application_id = b.loan_application_id AND a.due_date = b.max_date I want to convert this to DQL, I tried the following SELECT a.* FROM Loan\Entity\PaymentSchedule a, ( SELECT IDENTITY(ps2.loanApplication), MAX(ps2.dueDate) max_date FROM

Doctrine orm Zf2 form hydrate entity's value which is not in db

I have an Entity which has one property which is boolean and it is not use as a database column. Examle Entity { .. //other properties wich are @ORM/Column()... ... /** @var bool **/ protected isSetSomething; getIsSetSomething(){...} setIsSetSomething(){...} ... } My prblem is when binding object i use ClassMethods hydrator $this->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods(false)); but unfortunately when trying to acces $object->getIsSetSomethi

Doctrine orm Configure multiple databases in zf2 with doctrine2

How can I configure (and use) multiple databases in Zend Framework 2 with doctrine 2 ? Currently I have this in my local.php: return array( 'doctrine' => array( 'connection' => array( // default connection name 'orm_default' => array( 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 'params' => array( 'host' => 'localhost', 'port' => '3306', 'user' => 'root',

Doctrine orm Null Value on foreign key using OneToOne Relationship

The code is working except for the NULL value on person_id in Resume table. I can't figure out how to set value to it. I try this : $resume->setPerson($person); --> not working. \AppBundle\Entity\Person class Person { /** * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(type="string", length=100) */ private $name; /** * @ORM\OneToOne(targetEntity="Resume", mappedBy="person", cascade={"persist", "remove"

Doctrine orm Single Table Inheritance and Yaml configuration

I want to use in my project Single Table Inheritance for symfony2/doctrine, but I can't find any working examples with yaml configuration for it. In official documentation there is only annotation configuration presented. I found xml examples, but I want to use yaml configuration. Can somebody help and share with some working code?

Doctrine orm doctrine 2 query builder and join tables

I'm trying to get all comments for each post in my home page return $this->createQueryBuilder('c') ->select('c') ->from('Sdz\BlogBundle\Entity\Commentaire' ,'c') ->leftJoin('a.comments' ,'c')->getQuery()->getResult() ; but I'm getting this error [Semantical Error] line 0, col 58 near '.comments c,': Error: Identification Variable a used in join path expression but was not defined before. PS : The mapping is correct because I can see the page article with

Doctrine orm Doctrine: one to many relationship and cascade persistance

I mean I have these two classes (one to many relationship). As you can appreciate in both I have included cascade={"persist"}. namespace Project\FrontendBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="task") */ class Task { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", length=255, name="description", nullable=true) */

Doctrine orm ZF2 & Doctrine ORM - How to turn off the DoctrineModule cache

I have been wondering how to switch on and off the DoctrineModule cache in my development environment. Currently my queries are cached and stored in the data/DoctrineModule/cache folder and when bug testing this can cause constipation :) Essentially I would like to have caching set for my production environment and switched off for my development environment and to do this obviously I need the correct settings for the configs and to have a local/global config setting to deal with this. Here i

Doctrine orm Doctrine / Symfony: Yamldriver and SimpleYamlDriver compatibility in external library

I'm working on the creation of an external library that contains database information, such as entities, repositories and so on. The purpose is to use this library in symfony projects, but also in another project that support doctrine2. We encountered a problem in Yml files that contains entities configuration. We named it with dot to separate file path, and with the extension .dcm.yml as it was specified in doctrine documentation, it works fine in projects, but not in sf3 project... I searc

Doctrine orm CONCAT with COUNT, SUM,

In a complex query, I have a subquery to count/summarize children: ->addSelect('(SELECT CONCAT(COUNT(, \'|\', SUM(c.field1), \'|\', SUM(c.field2), \'|\', SUM(c.field3)) FROM App\Entity\Child c WHERE c.parent = GROUP BY c.parent)') This query worked perfectly until I upgraded to the new version of Symfony (4.2) and doctrine orm 2.6.1. I got the following error: [Syntax Error] line 0, col 25: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningSt

Doctrine orm Symfony 5 - One entity, one Repository and two Databases

I have a problem querying my database via Symfony Repository. If I don't specify a repository /** * ProductsText * * @ORM\Table(name="products_text") * @ORM\Entity */ i can select one of my databases by using Doctrine like this: ->getRepository(ProductsText::class, "db1"). But if i declare the repository: /** * ProductsText * * @ORM\Table(name="products_text") * @ORM\Entity(repositoryClass="App\Repository\Product\ProductsTextRepository") */

  1    2   3   4   5   6  ... 下一页 共 6 页