doctrine

Doctrine: many-to-many get removed associated object inside an event listener

蓝咒 提交于 2020-01-04 02:39:10
问题 I have many to many association like this Entity Car { /** * @var \Doctrine\Common\Collections\Collection * * @ORM\ManyToMany(targetEntity="User", inversedBy="cars", fetch="EXTRA_LAZY") * @ORM\JoinTable( * name="cars_users", * joinColumns={ * @ORM\JoinColumn(name="car_id", referencedColumnName="id") * }, * inverseJoinColumns={ * @ORM\JoinColumn(name="user_id", referencedColumnName="id") * } * ) */ protected $users; /** * @param $user */ public function removeUser(User $user) { if (!$this-

Custom error messages on doctrine validations

≯℡__Kan透↙ 提交于 2020-01-04 01:51:12
问题 I need to modify default error messages of doctrine validations. How can I do this? 回答1: CrazyJoe is right, in a way : it is not possible without some hard work :-( But, if you search hard enough, you might find a way ;-) With Doctrine 1.1, you model classes extend Doctrine_Record . That class defines this method : /** * Get the record error stack as a human readable string. * Useful for outputting errors to user via web browser * * @return string $message */ public function

Doctrine2: Type x already exists

倾然丶 夕夏残阳落幕 提交于 2020-01-03 20:33:09
问题 I have a problem with the Doctrine API. I want to add a new Doctrine Type. I followed this documentation to create the class, and I have added the type in my custom driver. Type::addType("custom", "Namespace\NameBundle\Types\CustomType"); $this->registerDoctrineTypeMapping("CustomType", "custom"); My problem append when I execute php app/console cache:clear. [Doctrine\DBAL\DBALException] Type custom already exists. After few searches, I have found in Doctrine\DBAL\Types\Type::addType(…) throw

Count Records Returned MySQL Doctrine

大兔子大兔子 提交于 2020-01-03 17:23:29
问题 How do I check the number of records returned from a search of my MySQL database with a statement like this: $searchKey = 'Something to search for'; $searchResults = Doctrine::getTable('TableName')->createQuery('t')- >where('columnName LIKE ?','%'.$searchKey.'%')->execute(); 回答1: maybe $searchResults->rowCount(); from here 回答2: Wouldn't Doctrine::getTable('TableName')->createQuery('t') ->where('columnName LIKE ?','%'.$searchKey.'%') ->execute() ->rowCount(); fetch the results from the

doctrine - get next and prev record

ε祈祈猫儿з 提交于 2020-01-03 13:08:12
问题 just so i have some record allready fetched. I have date field 'created' and now I want to get next and prev record by date. Got it working by: $qb = $this->createQueryBuilder('a'); $next = $qb->expr()->gt('a.created', ':date'); $prev = $qb->expr()->lt('a.created', ':date'); $prev = $qb->select('partial a.{id,title,created}') ->where($prev) ->setParameter('date', $date) ->orderBy('a.created', 'DESC') ->setMaxResults(1) ->getQuery() ->getArrayResult(); $next = $qb->select('partial a.{id,title

doctrine - get next and prev record

假如想象 提交于 2020-01-03 13:08:11
问题 just so i have some record allready fetched. I have date field 'created' and now I want to get next and prev record by date. Got it working by: $qb = $this->createQueryBuilder('a'); $next = $qb->expr()->gt('a.created', ':date'); $prev = $qb->expr()->lt('a.created', ':date'); $prev = $qb->select('partial a.{id,title,created}') ->where($prev) ->setParameter('date', $date) ->orderBy('a.created', 'DESC') ->setMaxResults(1) ->getQuery() ->getArrayResult(); $next = $qb->select('partial a.{id,title

persist new entity onFlush

浪子不回头ぞ 提交于 2020-01-03 11:29:34
问题 I try to user the onFlush Event in Doctrine to persist a new entity, but it leads to an infinite loop when trying to persist. Here is what I do in the Listener: $countusers = $em->getRepository('DankeForumBundle:NotificationUser')->countNotificationsByDeal($entity); if ($countusers > 0) { $notification = new NotificationAction(); $notification->setDeal($entity); $notification->setDatepost(new \DateTime()); $notification->setNotificationtype(NotificationAction::TYPE_TOP_DEAL); // $em is set to

Doctrine Migrations: There are no commands defined in the “” namespace

笑着哭i 提交于 2020-01-03 10:58:20
问题 I'm trying to setup Doctrine Migrations as a standalone program and am having a little bit of trouble. I have doctrine-migrations.phar and migrations.yml in the same folder. migrations.yml contains the following: name: Doctrine Sandbox Migrations migrations_namespace: DoctrineMigrations table_name: doctrine_migration_versions migrations_directory: /home/myusername/myproject/Database/Update Inside /home/myusername/myproject/Database/Update I have a file called Version20130608161001.php which

SELECT DISTINCT YEAR Doctrine

血红的双手。 提交于 2020-01-03 06:36:53
问题 I want to select distinct year from mysql database using doctrine: it is easy to do this using mysql SELECT DISTINCT DATE_FORMAT( year , '%Y') as dates FROM Inscription i don't find how to do this in doctrine documentation, anyone can help? 回答1: The SQL statement SELECT DISTINCT DATE_FORMAT( year , '%Y') as dates FROM Inscription can be written in Doctrine as follows: A. If you are writing a table method: class InscriptionTable extends Doctrine_Table { /* ... */ public function

generate-migrations-diff failing with Zend framework

只愿长相守 提交于 2020-01-03 06:32:33
问题 I am trying to generate a migration script using Doctrine with Zend Framework. I am getting the following: $ php doctrine.php generate-migrations-diff $ PHP Fatal error: Cannot redeclare class Avo_Model_AccessType in $ tmp/fromprfx_doctrine_tmp_dirs/AccessType.php on line 16 I can successfully build the models form the yaml file. I am using Zend Framework 1.10.5 and Doctrine 1.2.2 I think the issue might be with the autoloader and the fact that Zend Autoloads the classes that doctrine is