Questions tagged [doctrine-orm]

1

votes
1

answer
63

Views

Symfony/Doctrine2 and Associative entity

Usually when querying in a custom repository class, I use something like this : SELECT * FROM BundleName:Entity But how do I do for associative entity ? I have an entity 'Ticket' and an entity 'Tag'. It's a ManyToMany relation. In phpMyAdmin, I've got a ticket_tag associative table but how do I get...
Thibaut Tang
1

votes
1

answer
6.1k

Views

Composer/Doctrine 2 Class 'ComposerAutoloaderInit…' not found in vendor/autoload.php

This is driving me insane. Everything was moving along fine until I tried to change my composer.json file. Once I composer.update'ed I started getting this error in my log: PHP Fatal error: Class 'ComposerAutoloaderInite904d9fc0cad6e1b28066897f772cc3f' not found in /home/apache2/htdocs/doctrine/ven...
Ravioli87
1

votes
1

answer
141

Views

Swagger Invalid json message received

I'm using Symphony 4 with Doctrine and now I'm implementing / adding Swagger, so I will have proper docs where testing my api will be available. This is my postman, with proper inputed form data and OK response. And this are my 'problematic' notations of Swagger * @Route( * '/request', * na...
Valor_
1

votes
3

answer
3.8k

Views

Better way to get the SUM of the field of an associated entity in Doctrine 2?

How can I get the sum of the fields of an associated entity? For example, Invoice and Bill has OneToMany and ManyToOne relationship respectively, that is an Invoice can have many Bills. The Bill entity has an Amount column. How can an Invoice get the SUM of its related Bills' Amount?
Jeboy
1

votes
0

answer
52

Views

Unsupported index types through migrations. Schema:update wants to remove some

I have a symfony 3.4.2 + doctrine 2.6 project using postgresql 9.6. I am trying to add some unsupported index types. I found this issue which points out that migrations should be used for this purpose. My problem is that the migrations work for 2 out of 3 indices. But doctrine:schema:update wants 3r...
Evren Yurtesen
1

votes
3

answer
720

Views

How to handle deadlock in Doctrine?

I have a mobile application and server based on Symfony which gives API for the mobile app. I have a situation, where users can like Post. When users like Post I add an entry in ManyToMany table that this particular user liked this particular Post (step 1). Then in Post table I increase likesCounter...
Tom
1

votes
1

answer
46

Views

Is it possible to combine fetch joins and COUNT in Doctrine?

I want to fetch join some entities to avoid a lot of additional queries and I also want to get count of related collection. Something like this: SELECT u, a, count(p) properties_count FROM User u JOIN u.address a LEFT JOIN u.properties p group by u.id That is I want to get a collection like [[0 =>...
AlexP11223
1

votes
0

answer
73

Views

Remove all related children in Symfony entity ManyToOne

That is my relations: in CategoryField Entity: manyToOne: category: targetEntity: Category inversedBy: fields joinColumn: name: category_id referencedColumnName: id in Category: oneToMany: fields: orderBy: { 'name': 'ASC' } targetEntity: CategoryField mappedBy: category cascade: ['remove'] I'm tryi...
alias
1

votes
2

answer
74

Views

Doctrine : SELECT a relationned entity

I have 2 entities : LinkServInfra Serv LinkServInfra entity : id serv (relation OneToOne to Serv) infra (ManyToOne to another entity) Now, I'd like to get a list of Serv based on infra. So I tried in LinkServInfraRepository : $qb = $this->createQueryBuilder('s') ->select('DISTINCT s.serv') ->wher...
Bastien Nicolau
1

votes
2

answer
37

Views

@ORM\OneToMany Is retrieving the virtual deleted entries

I have a relation in Doctrine2 @ORM\OneToMany, suposing that i have table school and student, in the entity school i have the @ORM\OneToMany column students, and i also have a virtual deletion column deleted_at, so every student that has the deleted_at different of null is a deleted student that is...
Albert Abdonor
1

votes
2

answer
280

Views

Doctrine Class Table Inheritance can not remove() entity

I try to implement Doctrine's Class Table Inheritance. My Application needs a User Entity that is used to authenticate the user through Symfony's security system. On top of that, my application needs a special kind of User, a Doctor. Below you can find excerpts of my Entity classes. User class (Bas...
Momomentum
1

votes
1

answer
304

Views

Doctrine 2 Sementical Error couldn't find constant utilisateursadresses

I get this error [Semantical Error] Couldn't find constant utilisateursadresses, class Ecommerce\EcommerceBundle\Entity\Uti lisateursAdresses whene i try php app/console doctrine:generate:entities EcommerceBundle:UtilisateursAdresses my code : namespace Ecommerce\EcommerceBundle\Entity; use Doct...
Yassine Bayoudh
1

votes
1

answer
215

Views

Doctrine Fixtures Bundle wont install on Symfony 2.4.10

I am currently using symfony 2.4.10 i wanted to install Doctrine Fixtures Bundle but when i use composer require --dev doctrine/doctrine-fixtures-bundle to install it i get this : Your requirements could not be resolved to an installable set of packages. Problem 1 - symfony/doctrine-bridge v4.0.3 re...
Yassine Bayoudh
1

votes
1

answer
287

Views

Entity not Found Exception on Doctrine2

Scenario: I have two entities. Product & ProductGroup. Product has many to one relation to ProductGroup. I soft delete the ProductGroup. Then I try to call getProductGroup on a product which has a product group which was soft deleted. Problem: instead of expected null result I get an 'Message: Entit...
Shahzaib Hayat Khan
1

votes
1

answer
51

Views

doctrine 2: inheritance mapping join with parent table

I have a base table like this: class BaseProduct { /** * @ORM\ManyToOne(targetEntity='ProductBundle\Entity\Category', inversedBy='baseProducts') * @ORM\JoinColumn(name='menu_category_id', referencedColumnName='id', nullable=true) **/ protected $category; // ... and another entity that inherit from...
smoqadam
1

votes
1

answer
32

Views

Doctrine: Many to many query gives incomplete results

Ok, I got three tables 'articles', 'tags' and 'articles_tags', with a many-to-many relationship between the first two. Now I'm trying to query 'Find me all articles with the tag with ID 3' I've been trying this: $query = $em ->createQueryBuilder() ->select('a', 't') ->from('Models\Article', 'a') ->l...
Khales
1

votes
0

answer
578

Views

Doctrine DQL - count distinct multiple columns

I'm having a problem with counting some aggregations. Part of code looks like this: $qb->select($qb->expr()->countDistinct('policy.calculation', 'policy.id')) ->getQuery() ->getSingleScalarResult(); In sql it's possible to count distinct on multiple columns, and from DQL I'm getting an error: [Synt...
Oskar Gunther
1

votes
0

answer
75

Views

NULL values and data truncation due to automatic data types conversion

We are migrating from FreeTDS to Doctrine PDOSQLSrv or SQLSrv (trying both at the monent) and have encountered the problem with the data truncation of the fields that are not updated. Our update statements look like update tbl set field1 = isnull(?, field1), field2 = isnull(?, field2) where id = ? W...
pr0head
1

votes
1

answer
378

Views

Symfony 2: LIMIT Doctrine LEFT JOIN

I have a question about left join in doctrine in Symfony 2.7. Example code: public function test($id, $offset, $limit) { $build = $this->createQueryBuilder('building'); $build ->addSelect('users', 'numbers') ->join('building.users', 'users') // limit the numbers for 1 result! ->leftJoin('building.nu...
Car
1

votes
1

answer
78

Views

Doctrine : UniqueEntity on foreign property?

Is it possible to use a UniqueEntity annotation on a foreign object property ? For example I have two class : class A { private $id; private $num; /** * @ORM\ManyToOne(targetEntity='B' ....) */ private $b; ... } class B { private $id; private $sku; ... } I need to prevent users entering a A.num alre...
Bapt
1

votes
1

answer
76

Views

Doctrine2 Query Builder - Associative Data not hydrating correctly

I've got a somewhat complex query I'm writing on an X-Cart project (utilizes doctrine as the ORM). I have to query/pull records from several tables and ensure I'm not getting back irrelevant/empty results in the associated data. Here's what I'm running into: I have several inner joins that should be...
muzzledBYbrass
1

votes
1

answer
79

Views

DQL Query Doctrine places joined element OrderBy clause in another element's juncture condition's subQuery

Here is my situation: I gotta an entity User, with several joined entitites collections: class User { private $id; /** * @var UserData * @ORM\OneToMany(targetEntity='UserData', mappedBy='user') */ private $userDatas; /** * @var ServiceAccess * @ORM\OneToMany(targetEntity='ServiceAccess', mappedBy='u...
Cedo
1

votes
1

answer
561

Views

Symfony throwing ServiceCircularReferenceException

I am using Symfony 2.7 and i am writing all logs to data based on below tutorial https://nehalist.io/logging-events-to-database-in-symfony/ In service i have monolog.db_handler: class: AppBundle\Util\MonologDBHandler arguments: ['@doctrine.orm.entity_manager'] in monlog db handler i have following...
vision
1

votes
1

answer
28

Views

Doctrine selected joined objects

I have two two related entery (class): First class (Todo class): class Todo { /** * @var int * * @ORM\Column(name='id', type='integer') * @ORM\Id * @ORM\GeneratedValue(strategy='AUTO') */ private $id; } And Comment class(part): class Comment { /** * @var int * * @ORM\Column(name='id', type='integer'...
triest23
1

votes
1

answer
91

Views

Symfony 3.3.16 Doctrine Relations & Dictonary tables for fast data processing with Foms based on EntityType, can't pass choiced value to database

it's not a typical approach where 'user adds article'. This approach is a try to build nicely configurable, and data validated (by forms on frontend) table in database contains data based from other tables - something I'm trying to call 'Dictonary tables', and store ID in main table of of vchar rep...
zoore
1

votes
1

answer
284

Views

“NOT EXISTS” Query with Many to Many Relation Doctrine Symfony3

I would like to build a query that brings me all the games for a logged in user that he has not yet joined. For this I have built these 2 Entities. They are connected by many to many. class Game { public function __construct() { $this->users = new ArrayCollection(); } /** * @ORM\Column(type='integer...
Cadien
1

votes
1

answer
43

Views

What is a Doctrine-centric approach to work with repositories that use entities in mapped superclass configuration?

I have several entities that are related, such as McDoublePrice, CheeseburgerPrice, BigMacPrice, etc, which have a common BurgerPrice entity in a Mapped Superclass Doctrine configuration. How can I access a particular entity from my controller, action, or request handler? That is, I want the follow...
Dennis
1

votes
1

answer
58

Views

Symfony3 ManyToMany join

I need to get liste of articles who have the id of categorie with join ManyToMany I tried all day but it won't work. with dql query or anything pelase help I am despread. I want to get liste of articles who have category id with many to many relation /** * * @ORM\ManyToMany(targetEntity='Categorie'...
maher ben abdesslam
1

votes
0

answer
69

Views

Symfony4 / Doctrine2 / FOSRestBundle - Inserting / Updating entities

it's my first time here so I hope so don't be to hard on me ;) ! I'm trying to develop an API Rest on Symfony4 with FosRestBundle, Doctrine2 and JMSSerializer. Here's my problem : I have 3 entities organized such as : client which contains extras and a culture culture extra My annotations and associ...
Jérémy S.
1

votes
0

answer
41

Views

Doctrine 2.5.14: cascade remove don't working

I have two entities: Contrat and NoteContrat The ContratEntity's code: class ContratEntity { //... /** * @OneToMany(targetEntity='Contrat\Entity\NoteContratEntity', mappedBy='contrat', cascade={'remove'}) */ protected $noteContrat; //.. } The NoteContratEntity's code: class NoteContratEntity { //......
fatma_wings
1

votes
0

answer
65

Views

ManyToMany Relation in Symfony

I have two entities: categories and products, One product can refer to a variety of categories. I made ManyToMany relationships in the Doctrine, and that's what I get (code I'll add below). There is a table with the items (id, name, price, etc.), a table with categories (id, name, child_id) and the...
Dialkord
1

votes
1

answer
65

Views

Symfony 3 one-to-many, get parent with all children if one child satisfy the codition

I have these two tables I want to get all products(with all the children) that have at least one child with log_id = 13. Let's say I have the following rows in eorder_product_config table: The function that retrieves the products looks like this: public function getProducts($logId){ $q = $this ->cre...
Ceparu Stefan
1

votes
1

answer
48

Views

Update collection in relation manytomany in Doctrine with Symfony

I have 2 entities related with ManyToMany : Routage and Contact. Entity Routage : /** * @ORM\ManyToMany(targetEntity='AppBundle\Entity\Bdd\Contact', inversedBy='routages', cascade={'persist'}) * @ORM\JoinTable(name='routages_contacts') */ private $contacts; Entity Contact : /** * @ORM\ManyToMany(tar...
Florian Fish
1

votes
1

answer
85

Views

Why Easyadmin is not considering constraint in a ManyToMany relation

I have a ManyToMany relation and if I try to delete one related item from MySQL I'm blocked with an error; instead if I try to delete the same item from Easyadmin i'm not blocked. My expected behavior is to be blocked also by Easyadmin (v. 1.16 with Symfony v. 3.3.10). Please help... These are my 2...
Carlo Todeschini
1

votes
1

answer
103

Views

Business model with APIPlateform

We use Symfony 4 + Doctrine + APIPlateform to deliver a HTTP API. APIPlateform exposes Doctrine entities as API Rest resources (via annotation inside entity class), which (I found) no a good practice, since the business model (exposed by the API) should be the same than the Symfony Doctrine model. A...
Thomas Decaux
1

votes
0

answer
52

Views

improve my query symfony

Hello I am working on a project where i have large data. I have a Query that takes me more than 30 secondes which is so bad, that I hope someone can help me to improve it. ///////////////////////////// my repository // //////////////////////////// public function getr($id){ $q = $this->_em->createQu...
Abdelkrim peace
1

votes
0

answer
19

Views

Doctrine 2 how to count the Users that partecipate to an Event? (so a COUNT on GROUP BY)

I have 3 tables in my DB: user (_id, name) event (_id, name, ...) events_partecipants(user_id, event_id) I have two Doctrine entities which maps those tables and their relations and everything works (eg. I'm able to get all the partecipants for a specific event). Now, I want to retrieve the number o...
Noisemaker
1

votes
0

answer
55

Views

Doctrine Class inheritence id on child entity

Hi, In Doctrine 2.6.1: 6.3. Class Table Inheritance I use sql server 2014, Symfony 3.3, PHP 7.1.9
Kantin Charignon
1

votes
0

answer
34

Views

Doctrine ORM regex usage

How can I convert following MySQL query to doctrine code? I am trying to get some values from three columns using regex. SELECT * FROM job where CONCAT(title, company, description) REGEXP '^.*Officer.*$'; I tried this using direct SQL. $em = $this->getDoctrine()->getManager(); $sql = 'SELECT * FRO...
Reza
1

votes
0

answer
37

Views

EventListeners for log\history. Doctrine2, Symfony

I want to make custom log \ history in order to track what happened. I have such Entities: -Category -Item -AttrValue -Attributes All of them are related to each other like this: I read it and decided to use EventListeners and write events to the table using doctrine. You do not need to offer to use...
Dialkord

View additional questions