dql

Doctrine DQL returns multiple types of entities

老子叫甜甜 提交于 2019-12-23 21:54:53
问题 I have three entities: HandsetSubscription, Handset and Subscription. The yaml of HandsetSubscription is: App\SoBundle\Entity\HandsetSubscription: type: entity table: handset_subscription manyToOne: handset: targetEntity: Handset subscription: targetEntity: Subscription id: id: type: integer generator: { strategy: AUTO } options: { unsigned: true } fields: amount: type: integer nullable: false options: { default: 0, unsigned: true } discount: type: integer nullable: false options: { default:

Doctrine 2: Error: Class “..\..” has no field or association named “…”

假装没事ソ 提交于 2019-12-23 17:20:31
问题 When searching I came up with many results of people having similar problems but they were always related to association errors. I'm trying add a simple text field to a table in a database and, for the life of me, I can't figure out what's different about this time - when I've done it with no problems many times before. I've added a 'record_checksum' field to 4 different entities, but I will use just one, here to simplify the example. (The same error happens for all 4). Here is an example of

Doctrine2 Self Join, How to join on self without relationship column?

北城余情 提交于 2019-12-23 13:08:45
问题 Example mysql query: SELECT a1.* FROM agreement a1 LEFT JOIN agreement a2 on a1.agreementType = a2.agreementType and a2.id > a1.id WHERE a2.id is null The purpose of the query is to get the last agreement of the type returned. There are many types and I want only a listing of each latest agreement for each type. My example query above works as expected, but no go in DQL. How would I do this in DQL given I do not have a column that refers to itself? Note that "agreementType" is also a foreign

Select count() in Doctrine DQL with left join manyToMany unidirectional relation where user does NOT have relation specific group

最后都变了- 提交于 2019-12-23 09:04:32
问题 Situaction: I am trying to select count() in DQL for users NOT in specific group. Standard ManyToMany unidirectional relation between User and Group entities from FOSUserBundle (and SonataUserBundle ). System: Symfony 2.5, Doctrine 2.4. Entity User P.S. this is not real code copied. It is not possible because there are several layers extending with different config files in different formats and places, so if you spot mistype, this is not the problem. namespace RAZ\UserBundle\Entity; /** *

How can get unique values from data table using dql?

北战南征 提交于 2019-12-23 07:09:11
问题 I am having a table in which there is a column in which various values are stored.i want to retrieve unique values from that table using dql. Doctrine_Query::create() ->select('rec.school') ->from('Records rec') ->where("rec.city='$city' ") ->execute(); Now i want only unique values. Can anybody tell me how to do that... Edit Table Structure: CREATE TABLE IF NOT EXISTS `records` ( `id` int(11) NOT NULL AUTO_INCREMENT, `state` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `city` varchar

How to use Doctrine_RawSql for a fulltext search and sorting by relevance

旧街凉风 提交于 2019-12-23 01:21:07
问题 I'm trying to get fulltext searches to be sorted by relevance in a Doctrine_RawSql query. This code will perform the search: $q = new Doctrine_RawSql(); $q->select('{p.*}') ->from('cms_page p') ->where('match(p.content) against (?)', $user_query) ->addComponent('p', 'CmsPage p'); This will execute. I would like the results to be sorted by relevance The real sql would have to look something like: select p.id, match(p.content) against (?) as score from cms_page as p order by score desc; So I

How to export millions of rows from MySQL to CSV via PHP without exhausting memory?

巧了我就是萌 提交于 2019-12-22 09:17:12
问题 So I have this table: mysql> DESCRIBE table; +-------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+------------------+------+-----+---------+----------------+ | id | int(15) unsigned | NO | PRI | NULL | auto_increment | | unid | char(9) | NO | UNI | NULL | | | rs | varchar(255) | NO | | NULL | | +-------+------------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) Which contains millions of rows:

How to paginate a native query in Doctrine 2?

十年热恋 提交于 2019-12-21 06:24:13
问题 Doctrine 2 has the Doctrine\ORM\Tools\Pagination\Paginator class which can be used to paginate normal DQL queries. However if I pass it a native query, I get this error: Catchable fatal error: Argument 1 passed to Doctrine\ORM\Tools\Pagination\Paginator::cloneQuery() must be an instance of Doctrine\ORM\Query, instance of Doctrine\ORM\NativeQuery given I've tried removing the type-hinting from the paginator class in the cloneQuery method, but this just gives further errors because other bits

Parameters in DQL select statement (Symfony2/Doctrine)

怎甘沉沦 提交于 2019-12-21 05:34:12
问题 I'm trying to use external params in a DQL-s SELECT part, but it doesn't work due to an error. What I'm trying: $query = $this->getEntityManager() ->createQuery(" SELECT me.column_one, :param_doesnt_work param FROM CompanyMyBundle:MyEntity me WHERE me.column_one = :param_one AND me.column_two = :param_two ")->setParameters(array( 'param_doesnt_work' => 'A static value', 'param_one' => 'some param', 'param_two' => 'another param', )); I would like to get two columns as a result, the value of

Doctrine2 - How can I order by a discriminator column?

放肆的年华 提交于 2019-12-21 03:31:04
问题 How should I go about ordering by a discriminator column in a doctrine repository query? I have a pretty straight forward setup, I have different types of payment details, it can either be Credit Card (CC) or Debit Order (DO). So I've implemented a single table inheritance mapping strategy to achieve this, but the problem now comes in when I try to order by the discriminator column, since the discriminator column isn't present in the base class. The repository function: public function