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
87
votes
8 answers

Get the last insert id with doctrine 2?

How can I get the last insert id with doctrine 2 ORM? I didn't find this in the documentation of doctrine, is this even possible?
tom
  • 8,189
  • 12
  • 51
  • 70
86
votes
4 answers

How to use andWhere and orWhere in Doctrine?

WHERE a = 1 AND (b = 1 Or b = 2) AND (c = 1 OR c = 2) How can i make this in Doctrine? $q->where("a = 1"); $q->andWhere("b = 1") $q->orWhere("b = 2") $q->andWhere("c = 1") $q->orWhere("d = 2") this isnt correctly... Should be: $q->where("a =…
Paul Attuck
  • 2,229
  • 4
  • 23
  • 26
85
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,980
  • 9
  • 48
  • 74
84
votes
1 answer

Doctrine: cascade="remove" vs orphanRemoval=true

What is the difference between the 2 options above? When is it preferable to choose each option?
iiirxs
  • 4,493
  • 2
  • 20
  • 35
84
votes
1 answer

Understanding Doctrine Cascade Operations

I want to check my understanding of cascade operations on Doctrine associations. For the purpose of this question, I have two models: Customer and Insuree. If I define a many to many relationship between a Customer and Insuree and set…
user2406944
77
votes
2 answers

Doctrine 2 OneToMany Cascade SET NULL

The error Cannot delete or update a parent row: a foreign key constraint fails. The classes class Teacher { /** *@ORM\OneToMany(targetEntity="publication", mappedBy="teacher") */ protected $publications; } class Publication { …
Nicolas Lino
  • 771
  • 1
  • 5
  • 4
72
votes
3 answers

How do I delete an entity from symfony2

My first symfony2 project is a list of guests (invited in an event) stored in a database. I have created the entity class Guest with all variables for them (id, name, address, phone number etc.) created the schema in the mysql db created a route…
Radolino
  • 1,834
  • 4
  • 26
  • 48
72
votes
1 answer

Difference between ObjectManager and EntityManager in Symfony2?

What's the difference between Doctrine\Common\Persistence\ObjectManager and Doctrine\ORM\EntityManager when using it in a custom form type? I can get the respository using both $this->em->getRepository() and $this->om->getRepository(). class…
gremo
  • 47,186
  • 75
  • 257
  • 421
71
votes
1 answer

Symfony2: how to get all entities of one type which are marked with "EDIT" ACL permission?

Can someone tell me how to get all entities of one type which are marked with "EDIT" ACL permission? I would like to build a query with the Doctrine EntityManager.
stoefln
  • 14,498
  • 18
  • 79
  • 138
70
votes
7 answers

Best way to create a test database and load fixtures on Symfony 2 WebTestCase?

I have a WebTestCase that executes some basic routes in my application. I want to, on the setUp method of PHPUnit, create a test database identical to my main database, and load fixtures into it. I'm currently doing some workaround and executing…
Daniel Ribeiro
  • 10,156
  • 12
  • 47
  • 79
66
votes
12 answers

Generating a single Entity from existing database using symfony2 and doctrine

Is it possible to generate a single entity from database using the Symfony2 console tool? In the middle of coding I had to add a table and there are modifications made to the existing entity classes. So I don't want all my entities regenerated. Any…
Sethunath K M
  • 4,702
  • 3
  • 28
  • 42
64
votes
8 answers

PHPUnit Mock Objects and Static Methods

I am looking for the best way to go about testing the following static method (specifically using a Doctrine Model): class Model_User extends Doctrine_Record { public static function create($userData) { $newUser = new self(); …
rr.
  • 6,484
  • 9
  • 40
  • 48
55
votes
8 answers

Symfony2 Use Doctrine in Service Container

How do I use Doctrine in a service container? The Code just causes an error message "Fatal error: Call to undefined method ...::get()".
user1075510
  • 561
  • 1
  • 4
  • 5
55
votes
2 answers

Doctrine 2 Inheritance Mapping with Association

NOTE : if what I want is not possible, a "not possible" answer will be accepted In the Doctrine 2 documentation about inheritance mapping, it says there are 2 ways : Single table inheritance (STI) Class table inheritance (CTI) For both, there is…
Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
53
votes
9 answers

Checking for duplicate keys with Doctrine 2

Is there an easy way to check for duplicate keys with Doctrine 2 before doing a flush?
tom
  • 8,189
  • 12
  • 51
  • 70