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.

11146 questions
288
votes
14 answers

Doctrine2: Best way to handle many-to-many with extra columns in reference table

I'm wondering what's the best, the cleanest and the most simply way to work with many-to-many relations in Doctrine2. Let's assume that we've got an album like Master of Puppets by Metallica with several tracks. But please note the fact that one…
Crozin
  • 41,538
  • 12
  • 84
  • 134
180
votes
19 answers

Doctrine - How to print out the real sql, not just the prepared statement?

We're using Doctrine, a PHP ORM. I am creating a query like this: $q = Doctrine_Query::create()->select('id')->from('MyTable'); and then in the function I'm adding in various where clauses and things as appropriate, like…
Rory
  • 48,706
  • 67
  • 174
  • 234
126
votes
10 answers

PHP ORMs: Doctrine vs. Propel

I'm starting a new project with symfony which is readily integrated with Doctrine and Propel, but I of course need to make a choice.... I was wondering if more experienced people out there have general pros and/or cons for going with either of these…
Tom
  • 28,567
  • 26
  • 84
  • 120
118
votes
6 answers

Order by multiple columns with Doctrine

I need to order data by two columns (when the rows have different values for column number 1, order by it; otherwise, order by column number 2) I'm using a QueryBuilder to create the query. If I call the orderBy method a second time, it replaces any…
zootropo
  • 2,263
  • 3
  • 27
  • 44
114
votes
2 answers

Doctrine 2 can't use nullable=false in manyToOne relation?

An User has one Package associated with it. Many users can refer to the same package. User cannot exists without a Package defined. User should own the relation. Relation is bidirectional, so a Package has zero or more users in it. These…
gremo
  • 45,925
  • 68
  • 233
  • 380
107
votes
8 answers

Execute raw SQL using Doctrine 2

I want to execute raw SQL using Doctrine 2 I need to truncate the database tables and initialize tables with default test data.
Jiew Meng
  • 74,635
  • 166
  • 442
  • 756
102
votes
7 answers

Explicitly set Id with Doctrine when using "AUTO" strategy

My entity uses this annotation for it's ID: /** * @orm:Id * @orm:Column(type="integer") * @orm:GeneratedValue(strategy="AUTO") */ protected $id; From a clean database, I'm importing in existing records from an older database and trying to keep…
Eric
  • 1,897
  • 2
  • 15
  • 14
99
votes
1 answer

cascade={"remove"} VS orphanRemoval=true VS ondelete="CASCADE

I tried to gather some information about the following way to delete automatically child entity when a parent entity is deleted. Seems that the most common way is to use one those three annotation: cascade={"remove"} OR orphanRemoval=true OR…
Alexis_D
  • 1,758
  • 2
  • 14
  • 32
92
votes
13 answers

How to encode Doctrine entities to JSON in Symfony 2.0 AJAX application?

I'm developing game app and using Symfony 2.0. I have many AJAX requests to the backend. And more responses is converting entity to JSON. For example: class DefaultController extends Controller { public function launchAction() { …
Dmytro Krasun
  • 1,641
  • 1
  • 13
  • 19
90
votes
2 answers

What is Doctrine hydration?

I've read about hydration in doctrine's documentation but I still can't understand what it is. Could someone please explain?
never_had_a_name
  • 80,383
  • 96
  • 257
  • 374
84
votes
11 answers

Is there a built-in way to get all of the changed/updated fields in a Doctrine 2 entity

Let's suppose I retrieve an entity $e and modify its state with setters: $e->setFoo('a'); $e->setBar('b'); Is there any possibility to retrieve an array of fields that have been changed? In case of my example I'd like to retrieve foo => a, bar => b…
zerkms
  • 230,357
  • 57
  • 408
  • 498
83
votes
2 answers

How to specify null value as filter in a Doctrine query?

I am using Doctrine 1.1 in Zend. I am trying to write a query that will return records that have a null value in a certain column. $q = Doctrine_Query::create() ->select('a.*') ->from('RuleSet a') ->where('a.vertical_id = ?',…
Mr B
  • 3,553
  • 5
  • 41
  • 63
80
votes
2 answers

Deprecation: Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated

I'm using Symfony 4.3.8 and I can't find any information about thoses deprecations : User Deprecated: Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine ORM…
leobrl
  • 877
  • 1
  • 4
  • 14
78
votes
4 answers

How to re-save the entity as another row in Doctrine 2

Let's say I have entity $e. Is there any generic way to store it as another row, which would have the same entity data but another primary key? Why I need this: I'm implementing some sort of Temporal Database schema and instead of updating the row I…
zerkms
  • 230,357
  • 57
  • 408
  • 498
78
votes
3 answers

Doctrine 2: Update query with query builder

Hi I've got the following query but it doesn't seem to work. $q = $this->em->createQueryBuilder() ->update('models\User', 'u') ->set('u.username', $username) ->set('u.email', $email) ->where('u.id = ?1') ->setParameter(1,…
CarlM
  • 803
  • 1
  • 6
  • 5
1
2 3
99 100