Questions tagged [doctrine-orm]

Doctrine ORM is a PHP ORM. While Doctrine 1.2 uses the Active Record pattern, Doctrine ORM 2 and up uses the Data Mapper pattern. 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 ORM

Doctrine ORM is an object-relational mapper () for 5.4+ (starting with 2.6 version 7.1+). The Doctrine project is a collection of open source libraries and tools for dealing with database abstraction layer () and Object-Relational Mapping written in PHP. One of its key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language ().

Differences between Doctrine 1.2 and Doctrine 2.0.0

  • Doctrine 1.2 implements ActiveRecord design while Doctrine 2.0.0 implements DataMapper design
  • Doctrine 2.0.0 requires PHP 5.3 or newer and uses its benefits like namespaces.
  • Doctrine 2.0.0 is divided into set of smaller subprojects: Doctrine Commons, Doctrine DBAL, Doctrine ORM (for RDBMS) and Doctrine ODM (for MongoDB).
  • Doctrine 2.0.0 is much faster.
  • Doctrine 2.0.0 supports annotations.

Releases

Information

If you have questions about Doctrine 1.2, please use the tag instead.

Documentation

The documentation consists of:

  • Tutorials: Getting started articles
  • The Reference Guide: The main source of documentation for the project.
  • The Cookbook: A collection of simple and advanced recipes for using Doctrine.
  • An API for Doctrine
17177 questions
395
votes
16 answers

Default value in Doctrine

How do I set a default value in Doctrine 2?
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
293
votes
13 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
  • 43,890
  • 13
  • 88
  • 135
261
votes
3 answers

On delete cascade with doctrine2

I'm trying to make a simple example in order to learn how to delete a row from a parent table and automatically delete the matching rows in the child table using Doctrine2. Here are the two entities I'm using: Child.php:
rfc1484
  • 9,441
  • 16
  • 72
  • 123
237
votes
11 answers

Count Rows in Doctrine QueryBuilder

I'm using Doctrine's QueryBuilder to build a query, and I want to get the total count of results from the query. $repository = $em->getRepository('FooBundle:Foo'); $qb = $repository->createQueryBuilder('n') ->where('n.bar = :bar') …
Acyra
  • 15,864
  • 15
  • 46
  • 53
165
votes
3 answers

How to order results with findBy() in Doctrine

I am using the findBy() method on a Doctrine repository: $entities = $repository->findBy(array('type'=> 'C12')); How can I order the results?
Mirage
  • 30,868
  • 62
  • 166
  • 261
153
votes
14 answers

How to use WHERE IN with Doctrine 2

I have the following code which gives me the error: Message: Invalid parameter number: number of bound variables does not match number of tokens Code: public function getCount($ids, $outcome) { if (!is_array($ids)) { $ids =…
Tjorriemorrie
  • 16,818
  • 20
  • 89
  • 131
147
votes
2 answers

Why I am suddenly getting a "Typed property must not be accessed before initialization" error when introducing properties type hints?

I have updated my class definitions to make use of the newly introduced property type hints, like this: class Foo { private int $id; private ?string $val; private DateTimeInterface $createdAt; private ?DateTimeInterface…
yivi
  • 42,438
  • 18
  • 116
  • 138
140
votes
12 answers

How to sort findAll Doctrine's method?

I've been reading Doctrine's documentation, but I haven't been able to find a way to sort findAll() Results. I'm using symfony2 + doctrine, this is the statement that I'm using inside my…
ILikeTacos
  • 17,464
  • 20
  • 58
  • 88
139
votes
5 answers

Doctrine and composite unique keys

I want to do composite unique key in doctrine. Those are my fields: /** * @var string $videoDimension * * @Column(name="video_dimension", type="string", nullable=false) */ private $videoDimension; /** * @var string $videoBitrate * *…
Nikoole
  • 4,553
  • 4
  • 18
  • 23
137
votes
6 answers

How to get a one-dimensional scalar array as a doctrine dql query result?

I want to get an array of values from the id column of the Auction table. If this was a raw SQL I would write: SELECT id FROM auction But when I do this in Doctrine and execute: $em->createQuery("SELECT a.id FROM Auction a")->getScalarResult(); I…
Dawid Ohia
  • 16,129
  • 24
  • 81
  • 95
122
votes
4 answers

What is the difference between inversedBy and mappedBy?

I am developing my application using Zend Framework 2 and Doctrine 2. While writting annotations, I am unable to understand the difference between mappedBy and inversedBy. When should I use mappedBy? When should I use inversedBy? When should I use…
Developer
  • 25,073
  • 20
  • 81
  • 128
121
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
  • 47,186
  • 75
  • 257
  • 421
116
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
  • 2,037
  • 2
  • 16
  • 14
116
votes
2 answers

What is a Proxy in Doctrine 2?

I just finished reading all the Doctrine 2 documentation, I started my own sandbox, I understood most of the principes, but there is still a question and I couldn't find any complete explanation in the doc. What are Proxy classes? When should I…
Jérémy
  • 1,161
  • 2
  • 8
  • 3
115
votes
15 answers

"Class XXX is not a valid entity or mapped super class" after moving the class in the filesystem

I had an entity class in Aib\PlatformBundle\Entity\User.php I had no problems trying to create its form class through php app/ console doctrine:generate:form AibPlatformBundle:User Now I have change the namespace to…
tirenweb
  • 30,963
  • 73
  • 183
  • 303
1
2 3
99 100