Questions tagged [doctrine]

The Doctrine Project is a collection of open source libraries and tools for dealing with database abstraction and Object-Relational Mapping written in PHP.

The Doctrine Project is a collection of open source libraries and tools for dealing with database abstraction and Object-Relational Mapping written in PHP.


Doctrine 2

When we say Doctrine 2 it usually refers to Doctrine ORM Project. The ORM sits on top of the database abstraction layer (called DBAL). It also uses Doctrine Common (which provides extensions to core PHP functionality).

Side projects

Then you have side projects dedicated to some DBMS which provide transparent persistence for PHP objects:

Documentation

Useful links


Doctrine 1

The first version doesn't have a separate project for the relational mapper and the database abstraction layer. It requires PHP 5.2.3+ and the latest version is 1.2.5.

11930 questions
25
votes
3 answers

Converting MySQL to Doctrine Query Builder. Issues with IF and CONCAT. Or another approach for subqueries on select

I have a table for my categories, each category have and id, name and parent_id. Select IF(a.parent_id IS NULL, a.name, CONCAT((SELECT b.name FROM category b WHERE b.id = a.parent_id), " / ", a.name) ) as n, a.id, a.parent_id FROM category a ORDER…
Thiago Festa
  • 1,132
  • 1
  • 8
  • 14
25
votes
4 answers

Using column value as array index in doctrine

I am using doctrine 2.1 in order to create a model for settings table: id | arg | value | category 1 | name | foo | general_settings 2 | desc | bar | general_settings Suppose that I have a lot of setting for different…
manix
  • 14,537
  • 11
  • 70
  • 107
25
votes
4 answers

implementing "update if exists" in Doctrine ORM

I am trying to INSERT OR UPDATE IF EXISTS in one transaction. in mysql, I would generally use DUPLICATE KEY ("UPDATE ON DUPLICATE KEY".) I'm aware of many solutions to this problem using various SQL variants and sub-queries, but I'm trying to…
seans
  • 793
  • 2
  • 7
  • 19
24
votes
5 answers

insert ignore on duplicate entries in Doctrine2/Symfony2

How to ignore on duplicate entries using Doctrine2? Error example: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'symfony' for key 'UNIQ_389B783389B783'
seferov
  • 4,111
  • 3
  • 37
  • 75
24
votes
2 answers

Get date as a string from datetime object in doctrine 2

In one of my entities, I have a protected property called insert_date which is a datetime. When I extract the data afterwards, I don't get the date as a string, I get an object. My var dump:
dean jase
  • 1,161
  • 5
  • 23
  • 38
24
votes
4 answers

Doctrine_Core::getTable()->findAll() how to specify order?

When using a Doctrine_Table object, is it possible to specify the order of the returned collection when using findAll() or findByWhatever()? In the doc's I see some stuff about getOrderByStatement() and processOrderBy() but it isn't clear on how to…
Jake Wilson
  • 88,616
  • 93
  • 252
  • 370
24
votes
2 answers

In Doctrine 2 can the Fetch Mode (Eager/Lazy etc.) be changed at runtime?

I have entities which I would like to eagerly load , and on other ocassions lazy (or even extra lazy) load. My mappings have no fetch mode declared in my YAML- so they use the default (lazy loading). Currently the only way to eagerly load is to by…
calumbrodie
  • 4,722
  • 5
  • 35
  • 63
24
votes
2 answers

User Deprecated: Doctrine\Common\ClassLoader is deprecated

I am using Symfony 3.4.12 and can't find any information about how to solve this deprecation: User Deprecated: Doctrine\Common\ClassLoader is deprecated. Any suggestion?
Mutatos
  • 1,675
  • 4
  • 25
  • 55
24
votes
2 answers

Symfony doctrine auto_mapping Unrecognized

I have added SonataUserBundle and it is giving error config.yml doctrine: orm: auto_generate_proxy_classes: "%kernel.debug%" naming_strategy: doctrine.orm.naming_strategy.underscore auto_mapping: true …
Basit
  • 16,316
  • 31
  • 93
  • 154
24
votes
2 answers

Symfony 2 Doctrine find by ordered array of id

I'm looking for a way to use Doctrine in Symfony 2 to find items using an ordered array of id. I have a Card entity with id (primary key) and title. I have a ListCards entity with id (primary key) and a listCards (an array of ids encoded : ["16",…
Benjamin
  • 241
  • 1
  • 2
  • 4
24
votes
1 answer

Doctrine's Many-To-Many Self-Referencing and reciprocity

By default, self-referencing ManyToMany relationships under Doctrine involve an owning side and an inverse side, as explained in the documentation. Is there a way to implement a reciprocal association whithout difference between both…
albertedevigo
  • 18,262
  • 6
  • 52
  • 58
24
votes
2 answers

Symfony2 & Doctrine: Create custom SQL-Query

How can I create a custom SQL query in Symfony2 using Doctrine? Or without Doctrine, I don't care. Doesn't work like this: $em = $this->getDoctrine()->getEntityManager(); $em->createQuery($sql); $em->execute(); Thanks.
a1337q
  • 770
  • 3
  • 10
  • 20
24
votes
1 answer

Query with EXISTS for Doctrine Symfony2

How can I implement the following query with Query Builder? SELECT * FROM t WHERE t.status = 1 OR EXISTS(SELECT * FROM r WHERE r.t_id = t.id AND r.status = 1 ) The part without…
ArVan
  • 4,225
  • 8
  • 36
  • 58
23
votes
4 answers

Docblocks for Doctrine collections

Is there a standard way to document the expected class of entities inside a Collection in the docblock comment in a Doctrine project? Something like: /** * @var Collection */ protected $users; Looks like PHPDoc is the de-facto standard for…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
23
votes
9 answers

Importing tables from external database in Symfony2 with doctrine

I have a Symfony2 project with its own database, and now I want to connect to another database (another project) so I can modify some tables. I created the new connection in config_dev.yml doctrine: dbal: default_connection: default …
Sergi
  • 1,224
  • 3
  • 15
  • 34