doctrine

Symfony2/Doctrine - validation constraint which requires access to a database

三世轮回 提交于 2019-12-21 20:44:06
问题 I have an entity ArticlePattern , which has a property pattern (string). I need to access the database to check if pattern is correct. So I would like to define a method ArticlePattern::isPatternValid() and add a constraint (using Doctrine's annotation) which would check if isPatternValid is true during validation by Validator object. From what I have read here and there it is not a good idea, to make an entity depended on service container, which mean I cannot access the doctrine service

Doctrine 2 - ManyToMany + IN clause

岁酱吖の 提交于 2019-12-21 18:58:07
问题 I've got this model: /** @Entity @Table(name="articles") */ class Article { /** @Id @GeneratedValue @Column(type="integer") */ protected $id; /** @Column(type="string", length=100, nullable=true) */ protected $title; /** @ManyToOne(targetEntity="User", inversedBy="articles") */ protected $author; /** @Column(type="datetime") */ protected $datetime; /** * @ManyToMany(targetEntity="Game", inversedBy="articles") * @JoinTable(name="articles_games", * joinColumns={@JoinColumn(name="article_id",

Symfony2 - doctrine connection configuration in bundle

孤街醉人 提交于 2019-12-21 17:24:18
问题 I have project which uses my additional bundle. This bundle connects to other database and I need configuration for another database. I want to have this connections in 2 config files. main config: # ROOT/app/config/config.yml: doctrine: dbal: default_connection: default connections: default: driver: "%database_driver%" host: "%database_host%" port: "%database_port%" dbname: "%database_name%" user: "%database_user%" password: "%database_password%" charset: UTF8 bundle config: # src

Simple IF test statement in Doctrine

故事扮演 提交于 2019-12-21 17:01:50
问题 Does Doctrine support IF statements? I get the following error: Expected known function, got 'IF' while executing this query with IF: $qb->select("c.id, IF(c.type_id LIKE 9, c.name, c.lastname) as name") It works fine while re-written in pure SQL. Any workarounds? 回答1: Yes if statements in doctrine is not supported you may convert it to case when IF(c.type_id LIKE 9, c.name, c.lastname) as name to case when c.type_id = 9 then c.name else c.lastname end as name UPDATE: From the comment does

Remove Doctrine life cycle event from within a Symfony2 controller

吃可爱长大的小学妹 提交于 2019-12-21 12:32:14
问题 I am looking to remove a Doctrine Extensions life cycle event listener from within a controller. I need to remove the listener for update events because I need to update all nodes in the tree at once. Something that is not supported by the library, but is possible by directly setting the correct left, right, level etc... Is it possible to remove a life cycle even from within a controller? What is a possible solution for this situation. I thought something like this might work, but it did not

Use of closing database connection in php

此生再无相见时 提交于 2019-12-21 11:05:52
问题 I was always in assumption that it is always a good practice to close database connection, regardless of database/ORM, like mysql_close(), Propel::close() etc. With reference to one of my other question and some other research on Internet, I came to know a surprising face that most people recommends it doesn't really matter if you close connection as connection always gets closed after the request. However I'm finding those answers little difficult to digest. Reason is, why all DB lib, ORM

Symfony EntityRepository return instance of “Proxies\__CG__ MyModelName”

允我心安 提交于 2019-12-21 09:18:58
问题 Query $em->getRepository($this->getRepositoryName('AppBundle:User'))->find($id); return object instance of Proxies\__CG__\AppBundle\Entity\User instead of AppBundle\Entity\User . What the reason of this? 回答1: Doctrine is giving you a proxy object from an auto-generated class that extends your entity and implements \Doctrine\ORM\Proxy\Proxy . You can view the code for these auto-generated classes in app/cache/dev/doctrine/orm/Proxies/ . The proxy object allows for a set of behaviors that

Symfony EntityRepository return instance of “Proxies\__CG__ MyModelName”

五迷三道 提交于 2019-12-21 09:18:18
问题 Query $em->getRepository($this->getRepositoryName('AppBundle:User'))->find($id); return object instance of Proxies\__CG__\AppBundle\Entity\User instead of AppBundle\Entity\User . What the reason of this? 回答1: Doctrine is giving you a proxy object from an auto-generated class that extends your entity and implements \Doctrine\ORM\Proxy\Proxy . You can view the code for these auto-generated classes in app/cache/dev/doctrine/orm/Proxies/ . The proxy object allows for a set of behaviors that

Symfony2 Doctrine query

隐身守侯 提交于 2019-12-21 07:30:10
问题 I'm new in symfony2 , I don't know how to write a below query in symfony2 using createQuery() select * from Post inner join Category on Post.category_id=Category.id inner join Priority on Post.priority_id=Priority.id order by priority_number desc I used repository class,in which ,wrote a function public function findAllOrderedByPriorityPost() { return $this->getEntityManager() ->createQuery('select p,c,pr from RodasysfourmBundle:Post p inner join RodasysfourmBundle:Category c inner join

Symfony2 Doctrine query

我与影子孤独终老i 提交于 2019-12-21 07:30:02
问题 I'm new in symfony2 , I don't know how to write a below query in symfony2 using createQuery() select * from Post inner join Category on Post.category_id=Category.id inner join Priority on Post.priority_id=Priority.id order by priority_number desc I used repository class,in which ,wrote a function public function findAllOrderedByPriorityPost() { return $this->getEntityManager() ->createQuery('select p,c,pr from RodasysfourmBundle:Post p inner join RodasysfourmBundle:Category c inner join