php - How To Group By The Date Part Only In Doctrine -
i trying group results date not date time in doctrine.
here group statement of query:
group cast(fbaoh.datetimeplaced date) having sqty > 1 order fbaoh.datetimeplaced desc
this works in mysql not in doctrine, doing wrong?
here error get:
error: cannot group undefined identification or result variable. (500 internal server error)
thanks!
here entire query:
$query = $em->createquery(" select fbaoh, fbaoh.id fbaohid, sum(fbaoh.qty) sqty, p.id, p.name wic\apibundle\entity\fbaorderhistory fbaoh left join wic\listingbundle\entity\listingamazon la fbaoh.asin = la.standardproductidvalue left join wic\listingbundle\entity\listing l fbaoh.sku = l.product_identifier left join wic\productbundle\entity\product p l.product = p.id left join wic\listingbundle\entity\listingchannel lc l.listingchannel = lc.id fbaoh.webserviceaccountamazon = lc.webserviceaccount , fbaoh.sku = :sku , l.id = la.id , p.id != '' group cast(fbaoh.datetimeplaced date) having sqty > 1 order fbaoh.datetimeplaced desc ");
here had do: big props post.
i had create extended class use cast function.
namespace your\name\space; use doctrine\orm\query\ast\functions\functionnode; use doctrine\orm\query\lexer; class castfunction extends functionnode { public $firstdateexpression = null; public $unit = null; public function parse(\doctrine\orm\query\parser $parser) { $parser->match(lexer::t_identifier); $parser->match(lexer::t_open_parenthesis); $this->firstdateexpression = $parser->stringprimary(); $parser->match(lexer::t_as); $parser->match(lexer::t_identifier); $lexer = $parser->getlexer(); $this->unit = $lexer->token['value']; $parser->match(lexer::t_close_parenthesis); } public function getsql(\doctrine\orm\query\sqlwalker $sqlwalker) { return sprintf('cast(%s %s)', $this->firstdateexpression->dispatch($sqlwalker), $this->unit); } }
register in config.yml
doctrine: orm: dql: string_functions: cast: test\mybundle\dql\castfunction
then use in query:
$query = $em->createquery(" select fbaoh, cast(fbaoh.datetimeplaced date) groupdategrp, fbaoh.id fbaohid, sum(fbaoh.qty) sqty, p.id, p.name wic\apibundle\entity\fbaorderhistory fbaoh left join wic\listingbundle\entity\listingamazon la fbaoh.asin = la.standardproductidvalue left join wic\listingbundle\entity\listing l fbaoh.sku = l.product_identifier left join wic\productbundle\entity\product p l.product = p.id left join wic\listingbundle\entity\listingchannel lc l.listingchannel = lc.id fbaoh.webserviceaccountamazon = lc.webserviceaccount , fbaoh.sku = :sku , l.id = la.id , p.id != '' group groupdategrp having sqty > 1 order fbaoh.datetimeplaced desc ");
Comments
Post a Comment