query-builder

cakePHP 3 Query ifnull

让人想犯罪 __ 提交于 2019-12-02 13:25:01
问题 I wonder what would be the best way to prevent null results in a ResultSet. I'm on cake 3.5.13 and I'm using cases, like: private function addCase($isforeign, $source) { $query = $this->Sales->find(); return $query->newExpr() ->addCase( $query->newExpr()->add([ 'Sales.isforeign' => $isforeign, 'Sales.source' => $source ]), 1, 'integer'); } I then put the return of my addCase function in (..) 'sourcenationalcount' => $query->func()->sum($this->addCase(0, 1)), (..) Now it is possible that

doctrine 2 querybuilder with set parameters not working

泪湿孤枕 提交于 2019-12-02 13:13:57
问题 this is my query: public function getDetails($userid, $orderby, $sort){ $query = $this->_em->createQueryBuilder() ->select('u') ->from('\Entities\Users', 'u') ->where('u.userid= ?1') ->orderBy('u.?3', '?3') ->setParameter(1, $userid) ->setParameter(2, $orderby) ->setParameter(3, $sort) ->getQuery() ->getResult(); } it keeps erroring: Message: [Semantical Error] line 0, col 83 near '?3 DESC': Error: '?3' is not defined. how do i get the orderby from the properties in that function to the query

Invalid PathExpression. Must be a StateFieldPathExpression

蓝咒 提交于 2019-12-02 13:06:07
I get an error which is [Semantical Error] line 0, col 57 near 'room FROM AppBundle:bookings': Error: Invalid PathExpression. Must be a StateFieldPathExpression. I have two entities in AppBundle which are Room and Bookings. once I execute the query I get the error mentionned before. Here my query : $query = $em->createQuery( 'SELECT r ' . 'FROM AppBundle:Room r ' . 'WHERE r NOT IN ( ' . 'SELECT b.room ' . 'FROM AppBundle:Bookings b ' . 'WHERE NOT ( ' . 'b.check_out < :check_in ' . 'OR ' . 'b.check_in > :check_out ' . ')' . ') ' . 'ORDER BY r.id' ) ->setParameter('check_in', $request->query-

Laravel 4: multiple where with or in eloquent

寵の児 提交于 2019-12-02 10:30:53
how to write this condition using laravel eloquent SQL select count(id) from fight where status = 'finished' and (user1 = 1 or user2 = 1) Laravel (not finished): Fight::where('user1','=',$uid)->orWhere('user2', '=', $uid)->count('id'); thanks, This should do the work: Fight::whereStatus('finished')->where(function($q) use ($uid) { $q->where('user1',$uid)->orWhere('user2', $uid); })->count('id'); EDIT Answering comment: Fight::whereIn('status', ['finished', 'cancelled'])->where(function($q) use ($uid) { $q->where('user1',$uid)->orWhere('user2', $uid); })->count('id'); 来源: https://stackoverflow

What “type” do I specify in addCase to return a column?

扶醉桌前 提交于 2019-12-02 08:32:02
问题 I'm trying to get a query working using a case statement, and can't figure out how to get the case to return a column value instead of a constant. I have the query working perfectly, except that the column names I'm providing for the results are being quoted or otherwise mishandled by Cake or maybe PDO somewhere down in a layer that I can't dig my way through. I got as far down as bindValue, but none of the documentation I encountered along the way tells me how to do this. I have found this

doctrine2 queryBuilder must return only result matching with array values (ids): 0/Null and/or One and/or Many id(s) have to return One result

本小妞迷上赌 提交于 2019-12-02 08:14:14
问题 I have an array of collection named $configurations . This array matches of my Entity Configuration.php connected to Product.php as a ManyToMany . Now I have another entity named WorkType.php which is connected too to Configuration.php by a ManyToMany . The goal is to recover the product who has O/Null or Many configurations for the current work type. By default I have a product without configurations, but user could choose by checkboxes a O/Null or One or Many configurations available for a

How to compare two fields/columns in a condition?

蹲街弑〆低调 提交于 2019-12-02 05:33:38
问题 I am having a hard time trying to figure out how to get a sub-query working. Imagine I have: $schools ->select($this->Schools) ->select([ 'pupilcount' => $this->Pupils ->find() ->select([ $this->Pupils->find()->func()->count('*') ]) ->where([ 'Pupils.school_id' => 'Schools.id', ]), The problem I am experiencing (I think) is that Schools.id is always 0 and so the count is returned as 0. I can pull out the Pupils join and it shows Pupils there. I tried changing my code to add a: ->select(['SCID

query builder add condition on field type array

谁都会走 提交于 2019-12-02 05:20:19
问题 My question is simple : is it possible to add a where statment using doctrine and the query builder on a field type array ? Inside my entity I have the following : /** * @var array * * @ORM\Column(name="weekDays", type="array") */ private $weekDays; In the object view the array look like this: array( 1 => false, 2 => false, 3 => true, 4 => false, 5 => false, 6 => false, 7 => false ); an it's representation once serialize and inserted into the database look like this : a:7:{i:1;b:0;i:2;b:0;i:3

What “type” do I specify in addCase to return a column?

末鹿安然 提交于 2019-12-02 04:06:46
I'm trying to get a query working using a case statement, and can't figure out how to get the case to return a column value instead of a constant. I have the query working perfectly, except that the column names I'm providing for the results are being quoted or otherwise mishandled by Cake or maybe PDO somewhere down in a layer that I can't dig my way through. I got as far down as bindValue, but none of the documentation I encountered along the way tells me how to do this. I have found this example comment: $statement->bindValue(1, 'a title'); $statement->bindValue(2, 5, PDO::INT); $statement-

doctrine 2 querybuilder with set parameters not working

感情迁移 提交于 2019-12-02 02:49:56
this is my query: public function getDetails($userid, $orderby, $sort){ $query = $this->_em->createQueryBuilder() ->select('u') ->from('\Entities\Users', 'u') ->where('u.userid= ?1') ->orderBy('u.?3', '?3') ->setParameter(1, $userid) ->setParameter(2, $orderby) ->setParameter(3, $sort) ->getQuery() ->getResult(); } it keeps erroring: Message: [Semantical Error] line 0, col 83 near '?3 DESC': Error: '?3' is not defined. how do i get the orderby from the properties in that function to the query? You can't use placeholders for dinamical build of DQL query. You'll have to code it by your own: