PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] How to select all orders for which there is at least one bid cakephp 3.0?

 March 15, 2022     cakephp, cakephp-3.0, query-builder, select     No comments   

Issue

There are 2 table tables that are linked through a foreign key in a one-to-many relationship

table orders

and table bids

Need to select all orders to which there is at least one bid. On SQL this query is not difficult to do

SELECT * , count(bids.order_id) AS count_bid    
FROM orders
LEFT JOIN bids ON bids.order_id = orders.id
GROUP BY orders.id
HAVING (count_bid > 0)

but need make using the cakephp 3.0 query builder


Solution

As example:

$query = $this->Articles->find();
$query
  ->select(['count_bid' => $query->func()->count('Comments.id')])
  ->leftJoinWith('Comments')
  ->group(['Articles.id'])
  ->having(['count_bid >' => 0])
  ->enableAutoFields(true);
$results = $query->toArray();


Answered By - KoBa4
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing