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
16697 questions
356
votes
15 answers

Default value in Doctrine

How do I set a default value in Doctrine 2?
Jiew Meng
  • 74,635
  • 166
  • 442
  • 756
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
244
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
  • 8,473
  • 15
  • 58
  • 111
209
votes
10 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,026
  • 15
  • 41
  • 51
153
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
  • 28,544
  • 56
  • 155
  • 251
133
votes
13 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
  • 14,436
  • 15
  • 79
  • 119
126
votes
5 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
  • 14,918
  • 21
  • 73
  • 92
121
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
  • 13,823
  • 16
  • 52
  • 81
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
114
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,141
  • 2
  • 8
  • 3
110
votes
4 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
  • 3,863
  • 4
  • 16
  • 23
110
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
  • 21,956
  • 19
  • 72
  • 119
103
votes
9 answers

Too much data with var_dump in symfony2 doctrine2

I have around 40 entities and many bidirectional relationships. Whenever i use var_dump($user) or any entity my browser gets loaded with too much data of arrays and variables then it just crashed. i want to whats the problem. The data is being…
Mirage
  • 28,544
  • 56
  • 155
  • 251
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
97
votes
12 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…
ziiweb
  • 28,757
  • 70
  • 168
  • 290
1
2 3
99 100