query-builder

CakePHP Query - Conditional Based on Contain Field

折月煮酒 提交于 2020-01-07 05:37:09
问题 I am developing a system that holds reports from customer's computers and displays failures in a list. I am attempting to write a query that locates all systems that have currently failed or have failures in the past. My model for Computers has a field that says last_report_pass that allows me to quickly find computers that failed on the current day. My Reports are associated with a computer ID and has a field called status that says whether it was a pass or fail. I am attempting to write a

getting value from string array in cake php

妖精的绣舞 提交于 2020-01-07 03:56:09
问题 If I have this output of an array : $array_to_delete = [ (int) 3 => (int) 4, (int) 4 => (int) 5 ] And i want to get 4 and 5 and so on at where condition , Like that : $warehouseItemsData = $this->WarehouseEmployers->WarehouseItems->find() ->where(['id', $array_to_delete]) ->all(); How can i do that ? in cake php 回答1: use IN $warehouseItemsData = $this->WarehouseEmployers->WarehouseItems->find() ->where(['id IN', $array_to_delete]) ->all(); 来源: https://stackoverflow.com/questions/45481414

How to prevent showing/receiving untranslated content?

喜你入骨 提交于 2020-01-07 03:48:29
问题 This is my Distance Cell public function display() { $this->loadModel('Distances'); $distances = $this->Distances->find('all',[ 'order' => 'Distances.id ASC', ])->toArray(); $this->set('distances',$distances); }} Problem, if content is not yet translated and stored in db, original untranslated content is displayed on the page. How to prevent this, and show only translated content in current language? 回答1: The onlyTranslated option This is unfortunately not documented yet, but the Translate

Symfony2 and Doctrine Query with Distance (Lonigtude and Latitude) and large relationships - Weird result count?

核能气质少年 提交于 2020-01-07 00:40:07
问题 I have a large relationship models between many entities. Menu <> MenuSection <> Section <> SectionEntry <> Entry Entry <> EntryTag <> Tag Menu <> MenuLocation <> Location The Location entity got attributes like longitude and latitude to calculate the distance between the user's current position and the "location". I wrote a lil' bit larger doctrine query. YES, there are many relationships (many to many, many to one and so on, but the relation tables (e.g. entry_section) exist to store some

Symfony2 / Doctrine2 - How to convert this SQL request with QueryBuilder?

♀尐吖头ヾ 提交于 2020-01-06 07:04:17
问题 I have a relation : User -> [OneToMany] -> Profile <- [OneToMany] <- Group When a user joins a group, a profile is created with the couple user_id/group_id. And I want to get the unjoined groups from a user. This SQL request work good, but I want to translate it with QueryBuilder : For the user with id 2, SELECT g.id FROM Group g WHERE id NOT IN (SELECT group_id FROM Profile WHERE user_id = 2) Thanks for your help. 回答1: I didn't test it, but I think this should work $qb = $this->conn-

Symfony2 / Doctrine2 - How to convert this SQL request with QueryBuilder?

廉价感情. 提交于 2020-01-06 07:04:03
问题 I have a relation : User -> [OneToMany] -> Profile <- [OneToMany] <- Group When a user joins a group, a profile is created with the couple user_id/group_id. And I want to get the unjoined groups from a user. This SQL request work good, but I want to translate it with QueryBuilder : For the user with id 2, SELECT g.id FROM Group g WHERE id NOT IN (SELECT group_id FROM Profile WHERE user_id = 2) Thanks for your help. 回答1: I didn't test it, but I think this should work $qb = $this->conn-

UNION operator with QueryBuilder

风格不统一 提交于 2020-01-05 12:09:46
问题 I want to create a SELECT statement, which is a union of two sub-queries. Is there any way in ORMLite to create the two queries with QueryBuilder , and then concatenate them and create a UNION like this with a third QueryBuilder : SELECT * FROM ( FIRST SELECT UNION SECOND SELECT) WHERE isdefault = 0 ORDER BY someRow; someRow also changes dinamically. As for as i know QueryBuilder does not support UNION directly, so somehow i should inject the concatenated union into its statement. As the

How to use model events with query builder in laravel

限于喜欢 提交于 2020-01-05 07:33:27
问题 I'm using model events such as static::saving, static::saved, etc in my models' static function boot method, and that works great when users save new posts, but when I do something like this: $post::where('id', $post_id)->update(array('published'=>1)); Updating in this way does not run those model events. My current solution is to just not use this method of updating and instead do: $post = Post::find($post_id); $post->published = 1; $post->save(); But is there any way to make the model

How to write this query in query builder?

你。 提交于 2020-01-05 05:56:28
问题 I have the following (exemplary) query: SELECT * FROM User u LEFT JOIN section_user su ON (su.user_id = u.id AND su.section_id = 3) WHERE section_id is null I am trying to rebuild it in Symfony2 on a many-to-many relationship between users and sections with query builder but I am failing. I thought it would look like this, which proves to be wrong: $er->createQueryBuilder('u') ->leftJoin('u.sections', 's', 'WITH', 's = :section') ->where('s is null') ->setParameter('section', $section); Help

Recover values select imput related entities doctrine symfony 2

一笑奈何 提交于 2020-01-05 04:03:16
问题 I'm trying to create a form based on my related entities in doctrine by Symfony 2. I have different entities: Tematica, Personal, Hilo, Consultante, Consulta, Consulta_Asignatura and Asignatura. I reach to persist all my data, nevertheless have some problems with entities Hilo Personal and Tematica. In my form need to show select imput, it should have all "Enunciado" rows and later recover Email of selected option in this select input. I'll share my code, I hope somebody can help my. class