query-builder

Trying to update one table after inserting into another one with Symfony2 and Doctrine2

好久不见. 提交于 2019-12-01 12:22:00
问题 I wrote a function in BudgetRepository that is called when inserting new data into Budget table. The function is: public function addBudgetToClient($clientId, $budgetId) { return $this->createQueryBuilder('b') ->update('PanelBundle:Client', 'c') ->set('c.budget', $budgetId) ->where('c.id = ' . $clientId) ->getQuery() ->execute(); } And the BudgetController does this: public function addAction(Request $request) { $form = $this->createForm(new BudgetType()); $manager = $this->getDoctrine()-

Laravel query builder - How to either group by alias, or do raw groupBy

我是研究僧i 提交于 2019-12-01 04:18:51
My Laravel 5 app includes a dynamic query builder for report running. I need some group by clauses in there and have run into a problem. If I use actual sql in there I can have issues as sometimes there needs to be a sql command in amongst the sql (as opposed to straightforward column names), ie - DAYNAME(table_name.date_column) . Laravel mangles this: \`DAYNAME(table_name\`.\`date_column)\` For the select part of my query I can use selectRaw, but there does not seem to be an equivaent for group by. I thought of using aliases (all the selects are aliased) but Laravel wraps them in "`"

yii2 ActiveQuery 'OR LIKE' filter

☆樱花仙子☆ 提交于 2019-12-01 02:12:14
i have a task - add to search model searching by full name. Full name is first name + last name. So i need to build query like WHERE first_name LIKE '%var%' OR last_name LIKE '%var%' The only way i could do it : $query->andFilterWhere([ 'OR', 'profiles.first_name LIKE "%' . $this->userFullName . '%" ', 'profiles.last_name LIKE "%' . $this->userFullName . '%"' ]); But i dont like it because % its unsafe. I dont know how... I think there is the way to build such query with yii2 active builder, and i would like to get in result smth like $query->andFilterWhere(['LIKE', 'profiles.first_name',

Yii2: update field with query builder

老子叫甜甜 提交于 2019-12-01 02:07:06
How can I update field with query builder in Yii2? I can't find this in documentation. Thanks! UPD This is the solution: // UPDATE $connection = Yii::$app->db; $connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute(); Query builder is for select queries only (sum, max, count too). You should use other methods - AR or raw queries ( https://github.com/yiisoft/yii2/blob/master/docs/guide/db-dao.md#basic-sql-queries ) Create command can be used directly as follows : \Yii::$app->db->createCommand("UPDATE table SET column1=:column1, column2=:column2 WHERE id=:id") -

Laravel query builder - How to either group by alias, or do raw groupBy

折月煮酒 提交于 2019-12-01 00:35:18
问题 My Laravel 5 app includes a dynamic query builder for report running. I need some group by clauses in there and have run into a problem. If I use actual sql in there I can have issues as sometimes there needs to be a sql command in amongst the sql (as opposed to straightforward column names), ie - DAYNAME(table_name.date_column) . Laravel mangles this: \`DAYNAME(table_name\`.\`date_column)\` For the select part of my query I can use selectRaw, but there does not seem to be an equivaent for

Dynamic linq Building Expression

你离开我真会死。 提交于 2019-12-01 00:33:17
I need to create a dynamic linq expression for a dynamic search.The basic search is working but it fails to work with collection. I am able to get the book's title and author but fails to get the required page heading. I get the exception in line "left11 = Expression.Property(page1, "Heading");" . I think the expression that i built is unable to recognise the List. How could this be possible? Please see the below code and stacktrace exception. using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks;

How to get partial result from doctrine query builder

心已入冬 提交于 2019-12-01 00:00:39
I have a product entity in which it has an array as attributes: /** * @ORM\OneToMany(targetEntity="Shopious\MainBundle\Entity\ProductPicture", mappedBy="product", cascade={"persist","remove"}) */ protected $pictures; /** * @Accessor(getter="getCover") */ private $cover; public function getCover() { if($this->pictures->count() > 0) { return $this->pictures[0]; } return new ProductPicture(); } Now in my query builder, I have the following code: $query = $em->createQueryBuilder()->select('p') ->from("SiteMainBundle:Product", 'p') ->innerJoin('p.category', 'c') ->innerJoin('p.shop', 'shop') ; The

yii2 ActiveQuery 'OR LIKE' filter

旧城冷巷雨未停 提交于 2019-11-30 21:38:24
问题 i have a task - add to search model searching by full name. Full name is first name + last name. So i need to build query like WHERE first_name LIKE '%var%' OR last_name LIKE '%var%' The only way i could do it : $query->andFilterWhere([ 'OR', 'profiles.first_name LIKE "%' . $this->userFullName . '%" ', 'profiles.last_name LIKE "%' . $this->userFullName . '%"' ]); But i dont like it because % its unsafe. I dont know how... I think there is the way to build such query with yii2 active builder,

Laravel tag search to return images that contain all tags

不打扰是莪最后的温柔 提交于 2019-11-30 20:20:11
问题 I'm developing an application that lists images, and has multiple tags assigned to each image. I'd like to be able to find the images that are tagged with all of the tags being searched for. images table - id - download_url - image_width - image_height tags table - id - name image_tag table - id - image_id - tag_id In my model for Image , I've got belongsToMany('Tag') , and in my model for Tags , I've got belongsToMany('Image') . This is all working as I hoped, so far. However, my problem

Laravel Query Builder WHERE NOT IN

亡梦爱人 提交于 2019-11-30 20:12:26
I have the following sql query SELECT * FROM exams WHERE exams.id NOT IN (SELECT examId FROM testresults) how can I convert it into Laravel query builder format? Thanks. You can use whereNotIn with a closure: $result = DB::table('exams')->whereNotIn('id', function($q){ $q->select('examId')->from('testresults'); })->get(); 来源: https://stackoverflow.com/questions/28361461/laravel-query-builder-where-not-in