query-builder

Convert SQL with subquery to Doctrine Query Builder

好久不见. 提交于 2019-12-11 07:36:37
问题 I have follow database structure: List item trips (ManyToMany to tags over table trips_tags) +----+----------------+ | id | name | +----+----------------+ | 1 | Czech Republic | | 2 | Germany | | 3 | Poland | +----+----------------+ tags +----+-----------+ | id | name | +----+-----------+ | 1 | Mountains | | 2 | Beach | | 3 | City | +----+-----------+ trips_tags +----------+---------+ | trips_id | tags_id | +----------+---------+ | 1 | 1 | | 1 | 2 | | 3 | 1 | +----------+---------+ I need to

Are there ways to add 2 Table when using the INSERT statement in query builder?

試著忘記壹切 提交于 2019-12-11 05:45:53
问题 It seems like the query builder in vb only allow 1 table to use the INSERT statement, so are there any way add more than 1? 回答1: You should be able to wrap them all into one command call. Here is an example of what I think you are looking for. how to insert into two tables from vb.net 回答2: Using con As System.Data.SqlClient.SqlConnection = New SqlConnection("YourConnection string") con.Open() Dim cmd As New SqlCommand() Dim expression As String = "Parameter value" cmd.CommandType =

Symfony query => Error: Expected Literal, got '"'

巧了我就是萌 提交于 2019-12-11 04:22:29
问题 I have the following query: (it works fine without the addSelect('CASE ... END AS HIDDEN loquer') part which goals is to add some order into my comments. but with this part the following message from symfony is triggered: Error: Expected Literal, got '"' public function myfindArticleandCommentsandScores($article,$language){ $qb = $this->createQueryBuilder('a'); $qb->leftjoin('a.comments','c') ->addSelect('c') ->leftJoin('c.scores','s') ->addSelect('s') ->leftJoin('s.user','u') ->addSelect('u'

QueryBuilder/Doctrine Select join groupby

巧了我就是萌 提交于 2019-12-11 03:13:28
问题 So recently I have been thinking and can't find a solution yet to this problem since my lack of development with doctrine2 and symfony query builder. I have 2 tables: Goals: id,user_id,target_value... Savings: id,goal_id,amount And I need to make a select from goals (all the informations in my table are from the goals table, except that I need to make a SUM(amount) from the savings table on each goal, so I can show the user how much did he saved for his goal) This is the MySQL query: select

cakephp 3 queryBuilder for associative data

冷暖自知 提交于 2019-12-11 01:49:08
问题 I have 2 tables. Table 1: product_prices: id | price |description |pack |display |created |modified | Table 2: payment_infos: id |payer |pay_date |product_price_id |product_price | In the payment_infos model $this->belongsTo('ProductPrices', [ 'foreignKey' => 'product_price_id', 'className' => 'ProductPrices', ]); I have this query: $query = $this->find('all', [ 'contain' => ['ProductPrices'] ])); When running the above query I get the following error: Warning (512): Association property name

Laravel own variable in scope

谁说胖子不能爱 提交于 2019-12-11 00:34:31
问题 I'm using the haversine formula to calculate a distance, this is working fine. But I would like to hide results where the distance is greater then the max_radius field on that result. This is my database scheme. This is the query I'm using. You can see I hard coded the distance (50) public function scopeFitsDistance($query, $lat, $lng) { return $query->select(\DB::raw("*, ( 3959 * acos( cos( radians(?) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(?) ) + sin( radians(?) ) * sin(

Laravel order by conditions eloquent or sql

与世无争的帅哥 提交于 2019-12-10 21:42:53
问题 I have these timestamp columns in database table - expiration, edit, created_at. I need to order by 'edit', if item 'expiration' date is bigger than today's date, else I need to order by 'created_at'. I am trying something like this, but it isn't working correctly $items = $items ->orderBy(DB::raw("CASE WHEN expiration >= $time THEN edit ELSE created_at END"), 'DESC') ->get(); or $items = $items ->orderBy(DB::raw("CASE WHEN expiration >= $time THEN edit END"), 'DESC') ->orderBy('created_at',

Multiple call where in Yii Query builder

匆匆过客 提交于 2019-12-10 16:26:34
问题 I want to build query with multiple call where, but i have error, when use this code $command = Yii::app()->db->createCommand() ->select('*') ->from('{{table}}'); $command->where('value1 = :value1', array(':value1' => 1)); $command->where('value2 < :value2', array(':value2' => 2)); I understand, that i can use code like $command->where('value1 = :value1 AND value2 = :value2', array(':value1' => 1, ':value2' => 2)); but i have difficult conditions and simpler its use code like upper. In

Symfony2 and Doctrine2 - QueryBuilder with relational entities

拈花ヽ惹草 提交于 2019-12-10 11:29:40
问题 In my Symfony2 project, I have a query like this: $paperQB = $this->createQueryBuilder( 'p' ) ->select('p') ->where("p.title LIKE :q OR p.keywords LIKE :q OR p.abstract LIKE :q OR p.id LIKE :q") ->setFirstResult( $first_result ) ->setMaxResults( $papers_per_page ) ->orderBy($sort_by_culumn, $sort_by_order) ->setParameter('q', '%'.$q.'%'); Everything is fine there, but In my paper entity, I have a many to one relation with the section entity. So, I would like to get also: "OR p.section.name

Doctrine2: [Semantical Error] Cannot select entity through identification variables without choosing at least one root entity alias

一曲冷凌霜 提交于 2019-12-10 10:08:39
问题 This is my query with query builder, and it works perfectly, bringing all the results of user table and the modules table, which has a many to many association: public function getUser($id){ $qb = $this->getEm()->createQueryBuilder() ->select('u', 'm') ->from('Adm\Entity\User', 'u') ->join('u.modules', 'm') ->where('u.id = ?1') ->setParameters(array(1 => $id)); $result = $qb->getQuery()->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY); return $result; } But when i try to select specific