doctrine-1.2

Doctrine query returns extra field in result

时光总嘲笑我的痴心妄想 提交于 2020-01-06 20:58:55
问题 I have a Doctrine query; $q = Doctrine_Query::create()->select('s.monthly_volume') ->from('SearchVolume s') ->innerJoin('s.Keywords k') ->where('k.group_id = ?',array($group_id)); I just want it to return the monthly_volume value in the result array. It currently returns monthly_volume and id, I don't want it to return the id in result. 回答1: Doctrine automatically adds the primary key field to the results in almost every type of hydration mode. In a case like this where you want a simple

Doctrine query returns extra field in result

不问归期 提交于 2020-01-06 20:57:49
问题 I have a Doctrine query; $q = Doctrine_Query::create()->select('s.monthly_volume') ->from('SearchVolume s') ->innerJoin('s.Keywords k') ->where('k.group_id = ?',array($group_id)); I just want it to return the monthly_volume value in the result array. It currently returns monthly_volume and id, I don't want it to return the id in result. 回答1: Doctrine automatically adds the primary key field to the results in almost every type of hydration mode. In a case like this where you want a simple

Symfony - Add a column to a table without losing already generated classes

霸气de小男生 提交于 2020-01-05 07:30:03
问题 How can I add a column to a Database table without overwriting the classes already generated? (Doctrine) What files do I have to edit? If I simply add the column in the database, I can't use the set and get functions of Doctrine ORM. 回答1: Use doctrine migrations. It allows you to modify your schema, update the database and your model without also losing the existing data in your database (in case it is relevant). http://www.symfony-project.org/doctrine/1_2/en/07-Migrations Applicable for

Symfony - Add a column to a table without losing already generated classes

ⅰ亾dé卋堺 提交于 2020-01-05 07:29:02
问题 How can I add a column to a Database table without overwriting the classes already generated? (Doctrine) What files do I have to edit? If I simply add the column in the database, I can't use the set and get functions of Doctrine ORM. 回答1: Use doctrine migrations. It allows you to modify your schema, update the database and your model without also losing the existing data in your database (in case it is relevant). http://www.symfony-project.org/doctrine/1_2/en/07-Migrations Applicable for

My doctrine is Really Slow. Simple query and one second to get the result

限于喜欢 提交于 2020-01-04 12:15:21
问题 Here is my setup: Windows Server 2008 R2 MySql 5.1.562 Php 5.3.2 Doctrine 1.2 Anybody have an Idea why my query is taking about one second to perform a simple query. echo date("Y-m-d H:i:s", time()) ."::::::" . microtime(true)."<br />"; $q = Doctrine_Query::create() ->from("Ordering") ->where("client_id = ?",array($_SESSION["UserID"])); $ResProduct = $q->execute(); echo date("Y-m-d H:i:s", time()) ."::::::" . microtime(true)."<br />"; Here is the result of the 2 echo to show you how long it's

Conditional IF statement in a PHP Doctrine 1.2 SET statement

倖福魔咒の 提交于 2020-01-02 08:02:47
问题 I would like find the correct syntax for the SET line: Doctrine_Query::create() ->update('Media m') ->set('m.fallback IF(m.id = ?, 1, 0)', $id) <-- not correct ->execute(); Thanks for any help! 回答1: I think that could be done with two queries: Doctrine_Query::create() ->update('Media m') ->set('m.fallback', 1) ->where('m.id = ?', $id) ->execute(); Doctrine_Query::create() ->update('Media m') ->set('m.fallback', 0) ->where('m.id != ?', $id) ->execute(); I don't know if it suits you, but at

Conditional IF statement in a PHP Doctrine 1.2 SET statement

邮差的信 提交于 2020-01-02 08:02:10
问题 I would like find the correct syntax for the SET line: Doctrine_Query::create() ->update('Media m') ->set('m.fallback IF(m.id = ?, 1, 0)', $id) <-- not correct ->execute(); Thanks for any help! 回答1: I think that could be done with two queries: Doctrine_Query::create() ->update('Media m') ->set('m.fallback', 1) ->where('m.id = ?', $id) ->execute(); Doctrine_Query::create() ->update('Media m') ->set('m.fallback', 0) ->where('m.id != ?', $id) ->execute(); I don't know if it suits you, but at

How to query NOT NULL with Doctrine?

半腔热情 提交于 2019-12-30 07:55:47
问题 I have table Test: Test: id | name 1 | aaa 2 | 3 | ccc 4 | aaa 5 | 6 | ddd I want result where name is NOT NULL: aaa ccc aaa ddd How can i get with: Doctrine_Core::getTable('Test')->findBy('name', NOTNULL??) <-doesnt working and in model with: $this->createQuery('u') ->where('name = ?', NOTNULL ???) <- doesnt working ->execute(); 回答1: Try this: $this->createQuery('u') ->where('name IS NOT NULL') ->execute(); which is standard SQL syntax. Doctrine doesn't convert Null values into proper sql.

sfValidatorDoctrineUnique fails on capital letters

百般思念 提交于 2019-12-25 03:59:14
问题 I've setup a post validator in my symfony form to stop duplication of primary keys. A primary key is a two-character string in this instance. Code used to validate: $this->mergePostValidator(new sfValidatorDoctrineUnique(array( 'model' => 'Manufacturers', 'column' => 'id', 'primary_key' => 'id' ))); The primary key is uppercase (for example AU). Bizarrely the post validator triggers successfully is lowercase 'au' is entered into the field (i.e. stops it from going to the database and

doctrine how to write WhereIn() with another sql query inside

一笑奈何 提交于 2019-12-24 00:12:32
问题 i have the folowing query in SQL ... where group_id IN (select group_id from alert where monitor_id = 4); I want to write it in Doctrine but i don't know how to add the IN select into WHEREIN() clause ! any idea ? this is what i did $q = $this->createQuery('u') ->select('u.email_address') ->distinct(true) // ->from('sf_guard_user u') ->innerJoin('u.sfGuardUserGroup ug') ->where('ug.group_id IN(select group_id from alert where monitor_id=?',$monitor); $q->execute(); In the sfGuardUserTable