doctrine

PHP Doctrine - loading related records

Using Doctrine PHP If I have a user with a many to many relationship with the model address and each address has a foreign key to a address type (home, office). Doctrine doesn't automatically load the related records for that address type. $user = Doctrine::getTable('User')->findOneById(1); // bob echo $user->Address[0]->address_type_i...

Cumulative DQL with Doctrine

Hello Im having a hard time working out a proper DQL to generate cumulative sum. I can do it in plain SQL but when it comes to DQL i cant get hold of it. Here is how it looks in SQL: SELECT s.name, p.date_short, p.nettobuy, (select sum(pp.nettobuy) as sum from price pp where pp.stock_id = p.stock_id and p.broker_id = pp.brok...

Using a 'case when' in a Doctrine select statement

I have a select query I'd like to perform with Doctrine: $resultset = Doctrine_Query::create() ->select("t.code, t.description, case when t.id_outcome = 1 then 1 else 0 end as in_progress") ->from('LuOutcome t') ->orderBy('t.rank') ->fetchArray(); And it barfs on the 'case'. The documentation does not mention that it'...

Doctrine: How to remove part of a where clause from select query inside listener (preDqlSelect)?

My listener is part of a behavior, that should remove all is_published checks in the where clause of any called select query. Adding a part to a clause is really easy, but how to remove one. There are some functions like Doctrine_Query->removeDqlQueryPart('where'), but that removes the complete where clause, while I only need the 'is_...

doctrine orm: bypass lazy loading and prefetch related records in a getter

Working with Doctrine ORM, is it possible to enable auto eager loading of related records when using in a getter ? (without explicit leftJoins()) I know I can use a leftJoin() to obtain the object with related records, but I want to avoid creating a DQL query for every object and simply have some kind of automatic "prefetching" of rela...

How to make Doctrine use a MySQL TIMESTAMP column instead of DATETIME?

I'm looking for a way to use the MySQL timestamp column type in Doctrine 1.0. I was able to get it working by modifying Doctrine_DataDict_Mysql to return TIMESTAMP instead of DATETIME when the specified type is timestamp, but I'm fairly certain that it's not the right way, and it will probably break at some point. Doctrine 2.0 seems to ...

Doctrine PHP Question

I was wondering if you can specify the order in which table definitions and data fixtures are loaded using the CLI. My problem is that I have two tables, each having a foreign key constraint pointing to the other, so one of the constraints needs to be added after a record has been added. Or maybe there's a better way of doing this...I'm ...

Many-to-many relation with attributes in refClass

Hello, I'm currently designing a website, using symfony (1.2) with Doctrine as an ORM. I have a Dinner class, a Criteria class, and a Mark class. A Mark is linked with a Dinner and a Criteria, and has private attributes, like DateOfMark, MarkValue, etc. Dinner and Criteria can have many Marks (or none). As I use Doctrine, I defin...

Doctrine and Zend_Form Validation

I am using Zend Framework and Doctrine on a project and was wondering if anyone can suggest a good way to integrate Doctrine's validation with Zend_Form. I'm trying to avoid code duplication. ...

Doctrine migration foreign keys

In PHP Doctrine, is it possible to create one migration class that creates a table and creates a foreign key on that table? For some reason, I can't get the foreign key to work ... class Migration_001 extends Doctrine_Migration_Base { public function up() { $this->createTable('table_name', array(...)) $this->createFo...

how to resolve symfony doctrine:build-schema error (Unknown relation alias table_name)

how to resolve this symfony error : C:\inetpub\wwwroot\project\trunk\preprod\signup>php symfony doctrine:build-schema --trace >> doctrine generating yaml schema from database [sfException] Unknown relation alias table_name Exception trace: at C:\inetpub\wwwroot\project\trunk\preprod\signup\lib\vendor\symfony\lib\plugins\sfDoc...

Iterate Doctrine Collection ordered by some field

I need something like this: $products = Products::getTable()->find(274); foreach ($products->Categories->orderBy('title') as $category) { echo "{$category->title}<br />"; } I know is it not possible, but... How can I do something like this without creating a Doctrine_Query? Thanks. ...

Doctrine - filter by foreign agregate value

Hi there, how can i use result of Agregate function in where in Doctrine? For example i want to know user with silly much numbers. SELECT u.name, COUNT(p.id) AS users_phonenumber_count FROM users u INNER JOIN phonenumbers p ON p.user_id = u.id WHERE users_phonenumber_count > 10 GROUP BY u.id How can i access the *use...

Doctrine not Inserting Datetime in SQL Server

Doctrine ORM 1.0 inserts Datetime values in ISO8601 format; that is: '2009-10-23 12:31:22', but for some reason using SQL Server 2008 Express as my DB, throws an exception as if the value inserted was NULL. Here's the query: {sfDoctrineLogger} executeQuery : INSERT INTO [vbif_inventarios] ([anulado], [id_restaurante], [fecha_inventari...

Doctrine - How do you ask WHERE cond1 AND ( cond2 OR cond3)

While using Doctrine in a Symfony project I've come into the situation where I need to apply a condition and then one of two following conditions (which both happen to be sub-queries). I know of the andWhere() and orWhere() functions, but am having trouble using these to generate things like: WHERE cond1 AND ( cond2 OR cond3) ...

Symfony difference between <ModelName>.class.php and <ModelName>Table.class.php

Cuold someone explain me the difference between the Doctrine auto generated files .class.php and Table.class.php? For example in the Jobeet tutorial there's JobeetJob.class.php and JobeetJobTable.class.php (http://svn.jobeet.org/doctrine/trunk/lib/model/doctrine/sfJobeetPlugin/) I don't understand the role of each file and where I have ...

PHP Doctrine relationships and inheritance

Hi, I've been looking at Doctrine and it seems like a good way to manage models in my OO PHP application. I would like to create Models that have some optional properties. Rather than having null values in my database, I would like to create separate tables for some (all?) of these properties and give them a foreign key of the node w...

Doctrine ORM: Create Table Like Another

Hello, Is there any way, when using Doctrine, to create a table like another? I know in MySQL there is a function to do so: CREATE TABLE user2 LIKE user; and tables user and user2 will be identical. Can this be done in Doctrine? ...

PHP Doctrine ORM newbie - Valid DSN for dropping database?

Hi, I'm going through the tutorials for doctrine and liking it so far, however I'm stuck at the point of dropping/regenerating the db schema. This is the code I am using (pretty much straight from the tutorial) require_once(dirname(__FILE__) . '/lib/vendor/doctrine/Doctrine.php'); spl_autoload_register(array('Doctrine', 'autoload')); $...

Convert date to string upon saving a doctrine record

Hi, I'm trying to migrate one of my PHP projects to Doctrine. I've never used it before so there are a few things I don't understand. In my current code, I have a class similar to this: class ScheduleItem { private Date start; //A PEAR Date object. private Date end; public function getStart() { return $this->start; } public...