Skip Menu |
 

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 54949
Status: resolved
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: soporte [...] web-experto.com.ar
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.08119
Fixed in: 0.08250



Subject: Search with has_many relation fails at using ORDER BY RAND()
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 3856
Download (untitled) / with headers
text/plain 3.7k
Hi, first i apologies about my english, i will try to express my self the best i can. I found this issue that i detail next. Thanks DBIx-Class: DBIx-Class-0.08119 Perl Version: 5.8 OS: Ubuntu 8.10 package WEBEXPERTO::Modulos::Catalogue::Model::Product; use strict; use warnings; use base qw/DBIx::Class/; use base qw/WEBEXPERTO::Core::MEB::Model::Model/; __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); __PACKAGE__->table('catalogue_products'); __PACKAGE__->add_columns(qw/id_product id_node name_product description_product is_actived_product datetime_added_product datetime_last_modified_product date_start_publish_product date_finish_publish_product imagen_product resumen_product codigo_product destacado_product oferta_product skin_name/); __PACKAGE__->set_primary_key(qw/ id_product /); __PACKAGE__->has_many( 'productPrice' => 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', {'foreign.idProduct' => 'self.id_product'}, {cascade_delete => 0}, ); __PACKAGE__->has_one( 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', {'foreign.id' => 'self.id_node'}, {cascade_delete => 0}, ); 1; package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; use strict; use warnings; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto Core/); __PACKAGE__->table('catalogue_productPrices'); __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); __PACKAGE__->set_primary_key(qw/ id /); __PACKAGE__->has_one( 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', {'foreign.id' => 'self.idCurrency' }, ); __PACKAGE__->belongs_to( 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', {'foreign.id' => 'self.idPriceList' }, ); 1; #CODE my @productPrefetch; push(@productPrefetch,'node'); push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation my $searchAttributes = { prefetch => \@productPrefetch, rows => 3, order_by=> 'RAND()', #<-- cause the bug group_by => 'me.id_product', }; my $rsProducts = $schema->resultset('Product')->search({}, $searchAttributes); my $totalItems = $rsProducts->pager()->total_entries; What i expect is a set of products with has_many relation (productPrice) loaded with all prices. What i get is three products but eachone repeted 3 times, seems that group_by is not working. Sql query looks like this: SELECT me.id_product, me.id_node, me.name_product, me.description_product, me.is_actived_product, me.datetime_added_product, me.datetime_last_modified_product, me.date_start_publish_product, me.date_finish_publish_product, me.imagen_product, me.resumen_product, me.codigo_product, me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, productPrice.idProduct, productPrice.idPriceList, productPrice.idCurrency, productPrice.value, currency.id, currency.name, currency.symbol FROM (SELECT me.id_product, me.id_node, me.name_product, me.description_product, me.is_actived_product, me.datetime_added_product, me.datetime_last_modified_product, me.date_start_publish_product, me.date_finish_publish_product, me.imagen_product, me.resumen_product, me.codigo_product, me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, me.iva_product, me.marca_product FROM catalogue_products me GROUP BY me.id_product ORDER BY RAND() LIMIT 3) me LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; The last 'ORDER BY RAND()' mix up the product results (its seems like group_by is ignored). If you dont specify order_by attribute (with 'RAND()') its works just fine. If you need more details please let me know. Thanks again.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-14818-1267087489-480.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 5552
Download (untitled) / with headers
text/plain 5.4k
On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267073513-3964-0"
Message-ID: <20100225045153.88558B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 1F3654D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:45:45 -0500 (EST)
Received: (qmail 27101 invoked by uid 103); 25 Feb 2010 08:45:45 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:45:45 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:45:10 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id D7B63B5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:51:53 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hrNCrxTaapty for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:51:53 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 88558B5C583; Thu, 25 Feb 2010 01:51:53 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 01:51:53 -0300 (ART)
X-Spam-Level: *
To: "Peter Rabbitson via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14816-1267087562-1651.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To:
References: <RT-Ticket-54949 [...] rt.cpan.org>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14818-1267087490-33.54949-6-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
RT-Originator: ribasushi [...] cpan.org
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 34F78B5C582; Thu, 25 Feb 2010 01:51:53 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4W-okvUcUSQn; Thu, 25 Feb 2010 01:51:52 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id CA664B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 01:51:52 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 74B4836A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:55:50 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IwyUfT52RIqS for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:55:49 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 891D236A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:55:49 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id D4E0C7045; Thu, 25 Feb 2010 00:44:52 -0800 (PST)
Subject: [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:44:52 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
Content-Transfer-Encoding: 8bit
From: "Peter Rabbitson via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267073587-4005-0"
Message-ID: <20100225045307.1E47DB5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id BA66A4D801F for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:46:56 -0500 (EST)
Received: (qmail 30966 invoked by uid 103); 25 Feb 2010 08:46:56 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:46:56 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:46:21 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 749FDB5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:53:07 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FXyoNzNcncsY for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:53:07 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 1E47DB5C583; Thu, 25 Feb 2010 01:53:07 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 01:53:07 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14824-1267087632-1380.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225045153.88558B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225045153.88558B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14816-1267087564-1391.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267087564-14816-256"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id B62D1B5C582; Thu, 25 Feb 2010 01:53:06 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a6M7MwxGA33u; Thu, 25 Feb 2010 01:53:06 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 518B9B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 01:53:06 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 6D17F36A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:57:05 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QAUcd20Ygwcv for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:57:05 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id C80DB36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:57:04 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 29922704D; Thu, 25 Feb 2010 00:46:06 -0800 (PST)
Subject: [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:46:06 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738959/381681
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267073652-4022-0"
Message-ID: <20100225045412.9A650B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id DBEC54D801F for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:48:04 -0500 (EST)
Received: (qmail 2254 invoked by uid 103); 25 Feb 2010 08:48:04 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:48:04 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:47:29 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id D05A7B5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:54:14 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hVSofIIfCxQ2 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:54:12 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 9A650B5C583; Thu, 25 Feb 2010 01:54:12 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 01:54:12 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14816-1267087703-281.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225045307.1E47DB5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225045307.1E47DB5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14824-1267087633-348.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267087633-14824-249"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 3CAF3B5C582; Thu, 25 Feb 2010 01:54:12 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gMhlfslO8kqc; Thu, 25 Feb 2010 01:54:11 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id D2770B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 01:54:11 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 141B036A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:58:11 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sdtF-YF4m0e9 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:58:10 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 73D3C36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:58:10 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 831E3704C; Thu, 25 Feb 2010 00:47:14 -0800 (PST)
Subject: [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:47:14 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738962/381688
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738962/381689
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267073722-4047-0"
Message-ID: <20100225045522.D1099B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 0F2BF4D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:49:22 -0500 (EST)
Received: (qmail 6349 invoked by uid 103); 25 Feb 2010 08:49:22 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:49:22 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:48:43 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 9C417B5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:55:23 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pp0N+XnzCt48 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:55:22 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id D1099B5C583; Thu, 25 Feb 2010 01:55:22 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 01:55:22 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14812-1267087774-1679.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225045412.9A650B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225045412.9A650B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14816-1267087704-406.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267087704-14816-260"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 7D7C4B5C582; Thu, 25 Feb 2010 01:55:22 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6H-7pbfRFHed; Thu, 25 Feb 2010 01:55:22 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 216CDB5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 01:55:22 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 4970636A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:59:21 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8nSFlPyjoD9D for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:59:20 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 885C736A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 03:59:20 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 021FC704C; Thu, 25 Feb 2010 00:48:24 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:48:24 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738965/381696
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738965/381697
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738965/381698
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267073794-4061-0"
Message-ID: <20100225045634.B57BBB5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 213324D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:50:25 -0500 (EST)
Received: (qmail 9676 invoked by uid 103); 25 Feb 2010 08:50:24 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:50:24 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:49:49 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 1AD5AB5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:56:35 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id heO3O8rAB3Qn for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:56:34 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id B57BBB5C583; Thu, 25 Feb 2010 01:56:34 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 01:56:34 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14824-1267087834-567.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225045522.D1099B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225045522.D1099B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14812-1267087775-1780.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267087775-14812-261"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 5039EB5C582; Thu, 25 Feb 2010 01:56:34 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eF2XSTlrSBa6; Thu, 25 Feb 2010 01:56:33 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id E5BDDB5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 01:56:33 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 1AC3B36A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:00:34 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ls9Ebiqucuea for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:00:33 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 7F1CC36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:00:33 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 9AF5F704C; Thu, 25 Feb 2010 00:49:36 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:49:36 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738968/381705
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738968/381706
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738968/381707
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738968/381708
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267073854-4092-0"
Message-ID: <20100225045734.7D05CB5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 741124D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:51:39 -0500 (EST)
Received: (qmail 13590 invoked by uid 103); 25 Feb 2010 08:51:38 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:51:38 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:51:03 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id D8136B5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:57:34 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cbCQWEKMDDKo for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:57:34 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 7D05CB5C583; Thu, 25 Feb 2010 01:57:34 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 01:57:34 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14820-1267087910-1948.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225045634.B57BBB5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225045634.B57BBB5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14824-1267087835-497.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267087835-14824-253"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 292B4B5C582; Thu, 25 Feb 2010 01:57:34 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GQEzViJvyiF7; Thu, 25 Feb 2010 01:57:33 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id BE2AFB5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 01:57:33 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id E6B3336A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:01:34 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WqQTUAfO-h0B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:01:34 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 48FAB36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:01:34 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 280397045; Thu, 25 Feb 2010 00:50:36 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:50:36 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738971/381715
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738971/381716
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738971/381717
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738971/381718
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738971/381719
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267073928-4113-0"
Message-ID: <20100225045848.ABFB1B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 025BD4D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:52:40 -0500 (EST)
Received: (qmail 16944 invoked by uid 103); 25 Feb 2010 08:52:40 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:52:40 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:52:05 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 0D557B5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:58:49 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id emBnj6oF5we5 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:58:48 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id ABFB1B5C583; Thu, 25 Feb 2010 01:58:48 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 01:58:48 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14824-1267087971-1892.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225045734.7D05CB5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225045734.7D05CB5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14820-1267087911-1374.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267087911-14820-265"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 5006FB5C582; Thu, 25 Feb 2010 01:58:48 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dY9UTvtli4sY; Thu, 25 Feb 2010 01:58:47 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id E01ECB5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 01:58:47 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 165A436A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:02:49 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 59ND7CuPoedJ for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:02:48 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 6ABB036A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:02:48 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 635F5704C; Thu, 25 Feb 2010 00:51:52 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:51:52 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738974/381726
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738974/381727
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738974/381728
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738974/381729
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738974/381730
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738974/381731
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267073988-4129-0"
Message-ID: <20100225045948.17A0DB5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 5F1424D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:53:41 -0500 (EST)
Received: (qmail 20197 invoked by uid 103); 25 Feb 2010 08:53:40 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:53:40 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:53:06 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 6EF93B5C582 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:59:48 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4gDEA5CmN5bo for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 01:59:48 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 17A0DB5C583; Thu, 25 Feb 2010 01:59:48 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 01:59:48 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14813-1267088032-355.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225045848.ABFB1B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225045848.ABFB1B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14824-1267087971-1487.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267087971-14824-257"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id BADC8B5C582; Thu, 25 Feb 2010 01:59:47 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jyce+tOHlaPE; Thu, 25 Feb 2010 01:59:47 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 56A2EB5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 01:59:47 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id CCA9836A09E for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:03:49 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f4fAJTHg5quX for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:03:49 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 0E94F36A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:03:49 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 9AE50704C; Thu, 25 Feb 2010 00:52:52 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:52:52 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738977/381738
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738977/381739
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738977/381740
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738977/381741
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738977/381742
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738977/381743
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738977/381744
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074049-4445-0"
Message-ID: <20100225050049.2361CB5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 119A44D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:54:42 -0500 (EST)
Received: (qmail 23502 invoked by uid 103); 25 Feb 2010 08:54:42 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:54:42 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:54:07 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 8312CB5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:00:49 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id POsfwJYvK4Wi for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:00:49 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 2361CB5C583; Thu, 25 Feb 2010 02:00:49 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:00:49 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14824-1267088096-1715.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225045948.17A0DB5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225045948.17A0DB5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14813-1267088032-1530.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088032-14813-264"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id CE8CDB5C582; Thu, 25 Feb 2010 02:00:48 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0vxsi8plwTVl; Thu, 25 Feb 2010 02:00:48 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 62D3AB5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:00:48 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 64CB236A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:04:52 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id saNGEESwO8aI for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:04:51 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id A184336A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:04:51 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 58565704C; Thu, 25 Feb 2010 00:53:54 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:53:54 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738980/381751
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738980/381752
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738980/381753
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738980/381754
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738980/381755
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738980/381756
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738980/381757
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738980/381758
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074112-4465-0"
Message-ID: <20100225050152.CE3EBB5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 1F96E4D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:55:47 -0500 (EST)
Received: (qmail 26962 invoked by uid 103); 25 Feb 2010 08:55:46 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:55:46 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:55:11 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 2BAA2B5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:01:53 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aP9hwud-06xR for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:01:52 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id CE3EBB5C583; Thu, 25 Feb 2010 02:01:52 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:01:52 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14831-1267088157-198.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225050049.2361CB5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225050049.2361CB5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14824-1267088097-1992.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088097-14824-261"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 8AEADB5C582; Thu, 25 Feb 2010 02:01:52 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E7NCvQhiJAY1; Thu, 25 Feb 2010 02:01:52 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 2AA91B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:01:52 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 11A8E36A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:05:56 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TDt1lgn2FML1 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:05:55 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 4C78436A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:05:55 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 4FAE2704C; Thu, 25 Feb 2010 00:54:58 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:54:58 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738983/381765
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738983/381766
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738983/381767
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738983/381768
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738983/381769
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738983/381770
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738983/381771
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738983/381772
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738983/381773
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074175-4497-0"
Message-ID: <20100225050255.1DFD7B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 610E84D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:56:50 -0500 (EST)
Received: (qmail 30400 invoked by uid 103); 25 Feb 2010 08:56:49 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:56:49 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:56:15 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 6D60FB5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:02:55 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7o9AJV+E1LPV for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:02:55 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 1DFD7B5C583; Thu, 25 Feb 2010 02:02:55 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:02:55 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14818-1267088222-381.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225050152.CE3EBB5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225050152.CE3EBB5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14831-1267088158-3.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088158-14831-241"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id D043AB5C582; Thu, 25 Feb 2010 02:02:54 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j+n4IdVxllau; Thu, 25 Feb 2010 02:02:54 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 6CAA6B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:02:54 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 368BB36A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:06:59 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6smwyKc6J8KR for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:06:58 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 8323E36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:06:58 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 4BE00704D; Thu, 25 Feb 2010 00:56:00 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:56:00 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381780
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381781
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381782
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381783
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381784
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381785
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381786
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381787
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381788
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738986/381789
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074237-4515-0"
Message-ID: <20100225050357.DCC6DB5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id B8B164D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:57:53 -0500 (EST)
Received: (qmail 1610 invoked by uid 103); 25 Feb 2010 08:57:53 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:57:53 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:57:18 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 3A087B5C582 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:03:58 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H7s0ZvkctSb1 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:03:57 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id DCC6DB5C583; Thu, 25 Feb 2010 02:03:57 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:03:57 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14824-1267088283-1865.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225050255.1DFD7B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225050255.1DFD7B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14818-1267088223-859.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088223-14818-268"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 8EA39B5C582; Thu, 25 Feb 2010 02:03:57 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id obZMfXaAZCQW; Thu, 25 Feb 2010 02:03:57 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 299A3B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:03:57 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 6819236A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:08:03 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ps8WUbQwdyPH for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:08:03 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id B09CF36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:08:02 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id BAF37704C; Thu, 25 Feb 2010 00:57:04 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:57:04 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381796
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381797
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381798
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381799
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381800
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381801
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381802
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381803
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381804
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381805
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738989/381806
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074298-4534-0"
Message-ID: <20100225050458.5FC65B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 63AF84D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 03:58:54 -0500 (EST)
Received: (qmail 4925 invoked by uid 103); 25 Feb 2010 08:58:53 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:58:53 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:58:19 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id C3446B5C582 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:04:58 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2hAV4pxug46n for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:04:58 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 5FC65B5C583; Thu, 25 Feb 2010 02:04:58 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:04:58 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14812-1267088347-1662.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225050357.DCC6DB5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225050357.DCC6DB5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14824-1267088284-203.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088284-14824-265"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 17061B5C582; Thu, 25 Feb 2010 02:04:58 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DgNvzgxliU7d; Thu, 25 Feb 2010 02:04:57 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 9CC08B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:04:57 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id A565236A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:09:04 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MdWpEe3staaJ for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:09:04 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id B812F36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:09:03 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 603ED704C; Thu, 25 Feb 2010 00:58:05 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:58:05 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381813
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381814
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381815
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381816
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381817
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381818
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381819
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381820
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381821
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381822
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381823
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738992/381824
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074364-4547-0"
Message-ID: <20100225050605.21DD0B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 814374D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 04:00:00 -0500 (EST)
Received: (qmail 8557 invoked by uid 103); 25 Feb 2010 08:59:59 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 08:59:59 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 00:59:25 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 92264B5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:06:05 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kuY8qW87siHy for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:06:05 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 21DD0B5C583; Thu, 25 Feb 2010 02:06:04 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:06:04 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14818-1267088417-860.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225050458.5FC65B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225050458.5FC65B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14812-1267088348-449.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088348-14812-265"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id B6110B5C582; Thu, 25 Feb 2010 02:06:03 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mNc1RuXXoRv8; Thu, 25 Feb 2010 02:06:03 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 4090EB5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:06:03 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id C736736A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:10:09 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LYTQcXH7YagO for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:10:08 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 7B19D36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:10:08 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 8EA8F704C; Thu, 25 Feb 2010 00:59:09 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 03:59:09 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381831
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381832
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381833
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381834
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381835
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381836
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381837
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381838
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381839
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381840
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381841
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381842
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/738995/381843
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074437-4576-0"
Message-ID: <20100225050717.77315B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 33B614D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 04:01:12 -0500 (EST)
Received: (qmail 12517 invoked by uid 103); 25 Feb 2010 09:01:11 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 09:01:11 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 01:00:36 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id D4C90B5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:07:17 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4ROVjkJsRlV0 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:07:17 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 77315B5C583; Thu, 25 Feb 2010 02:07:17 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:07:17 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14824-1267088482-1497.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225050605.21DD0B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225050605.21DD0B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14818-1267088420-1722.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088420-14818-272"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 23CDEB5C582; Thu, 25 Feb 2010 02:07:17 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WHo3BP7U8HEJ; Thu, 25 Feb 2010 02:07:16 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 9640BB5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:07:16 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 6661F36A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:11:22 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kcyQ8jC6AlJB for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:11:22 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id AF20936A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:11:21 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id EC1CF704D; Thu, 25 Feb 2010 01:00:22 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 04:00:22 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381852
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381853
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381854
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381855
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381856
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381857
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381858
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381859
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381860
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381861
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381862
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381863
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381864
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739002/381865
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074498-4593-0"
Message-ID: <20100225050819.31290B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id B06C44D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 04:02:14 -0500 (EST)
Received: (qmail 15846 invoked by uid 103); 25 Feb 2010 09:02:14 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 09:02:14 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 01:01:39 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id AB26BB5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:08:19 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sMKAN7LoXECs for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:08:19 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 31290B5C583; Thu, 25 Feb 2010 02:08:18 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:08:18 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14831-1267088546-1998.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225050717.77315B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225050717.77315B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14824-1267088483-1957.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088483-14824-269"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 07DC8B5C582; Thu, 25 Feb 2010 02:08:18 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yNokzyCqYL2o; Thu, 25 Feb 2010 02:08:17 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 8EB7EB5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:08:17 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 017FC36A090 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:12:22 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nr26Apoq1PAZ for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:12:21 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 3170436A08F for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:12:21 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 6CA0F704D; Thu, 25 Feb 2010 01:01:24 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 04:01:24 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381872
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381873
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381874
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381875
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381876
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381877
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381878
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381879
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381880
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381881
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381882
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381883
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381884
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381885
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739005/381886
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074565-4620-0"
Message-ID: <20100225050925.4386AB5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 9D9544D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 04:03:20 -0500 (EST)
Received: (qmail 19507 invoked by uid 103); 25 Feb 2010 09:03:19 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 09:03:19 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 01:02:45 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id A7D6CB5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:09:25 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N-QIwi8KPTzT for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:09:25 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id 4386AB5C583; Thu, 25 Feb 2010 02:09:25 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:09:25 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14824-1267088610-1468.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225050819.31290B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225050819.31290B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14831-1267088547-954.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088547-14831-246"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id E6A2EB5C582; Thu, 25 Feb 2010 02:09:24 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6xoV4FUP4R5k; Thu, 25 Feb 2010 02:09:24 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 723F7B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:09:24 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 609B936A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:13:28 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lMeUlEXpNa-F for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:13:27 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 90FC936A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:13:27 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 7A0DA704D; Thu, 25 Feb 2010 01:02:31 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 04:02:31 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381893
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381894
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381895
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381896
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381897
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381898
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381899
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381900
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381901
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381902
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381903
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381904
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381905
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381906
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381907
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739008/381908
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074625-4640-0"
Message-ID: <20100225051025.AA0C2B5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id D706B4D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 04:04:21 -0500 (EST)
Received: (qmail 22752 invoked by uid 103); 25 Feb 2010 09:04:21 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 09:04:21 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 01:03:46 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 187A5B5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:10:26 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bTCJ2FVZGz7N for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:10:25 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id AA0C2B5C583; Thu, 25 Feb 2010 02:10:25 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:10:25 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14820-1267088671-155.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225050925.4386AB5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225050925.4386AB5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14824-1267088611-392.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088611-14824-273"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 585DFB5C582; Thu, 25 Feb 2010 02:10:25 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Zk0aU1uYv9qX; Thu, 25 Feb 2010 02:10:24 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id DAD01B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:10:24 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 2FD8336A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:14:28 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VdWwhVCGETZs for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:14:27 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 7405E36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:14:27 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id BCDD1704E; Thu, 25 Feb 2010 01:03:32 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 04:03:32 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381915
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381916
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381917
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381918
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381919
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381920
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381921
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381922
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381923
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381924
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381925
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381926
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381927
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381928
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381929
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381930
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739011/381931
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=
X-Mailer: ispCP 1.0.2 OMEGA Autoreply Manager
X-Autoresponse-From: macevedo [...] web-experto.com.ar
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
Content-Type: multipart/mixed; boundary="----------=_1267074685-4654-0"
Message-ID: <20100225051125.CC12AB5C583 [...] panel.descartes.web-experto.com>
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 8A0CB4D801C for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 04:05:23 -0500 (EST)
Received: (qmail 26047 invoked by uid 103); 25 Feb 2010 09:05:22 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 25 Feb 2010 09:05:22 -0000
Received: from panel.descartes.web-experto.com (HELO panel.descartes.web-experto.com) (67.205.118.19) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Thu, 25 Feb 2010 01:04:48 -0800
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 3667DB5C560 for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:11:26 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Tz5Jg-LoO4au for <bug-DBIx-Class [...] rt.cpan.org>; Thu, 25 Feb 2010 02:11:25 -0300 (ART)
Received: by panel.descartes.web-experto.com (Postfix, from userid 1001) id CC12AB5C583; Thu, 25 Feb 2010 02:11:25 -0300 (ART)
Delivered-To: cpan-bug+DBIx-Class [...] diesel.bestpractical.com
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
Return-Path: <vmail [...] panel.descartes.web-experto.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBIx-Class [...] rt.cpan.org
Date: Thu, 25 Feb 2010 02:11:25 -0300 (ART)
X-Spam-Level: *
To: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: macevedo [...] web-experto.com.ar
RT-Message-ID: <rt-3.8.HEAD-14831-1267088734-1918.54949-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Description: Mail User Autoreply Message
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 179
Download (untitled) / with headers
text/plain 179b
En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
Content-Description: Original Message
Content-Type: message/rfc822
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
In-Reply-To: <20100225051025.AA0C2B5C583 [...] panel.descartes.web-experto.com>
References: <RT-Ticket-54949 [...] rt.cpan.org> <20100225051025.AA0C2B5C583 [...] panel.descartes.web-experto.com>
Reply-To: bug-DBIx-Class [...] rt.cpan.org
X-Virus-Scanned: Debian amavisd-new at panel.descartes.web-experto.com
X-Virus-Scanned: Debian amavisd-new at mx1.descartes.web-experto.com
Message-ID: <rt-3.8.HEAD-14820-1267088672-869.54949-6-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267088672-14820-269"
RT-Originator: macevedo [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Managed-BY: RT 3.8.HEAD (http://www.bestpractical.com/rt/)
Received: from localhost (panel.descartes.web-experto.com.local [127.0.0.1]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 7B88EB5C582; Thu, 25 Feb 2010 02:11:25 -0300 (ART)
Received: from panel.descartes.web-experto.com ([127.0.0.1]) by localhost (panel.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lTF+8XoTgKSp; Thu, 25 Feb 2010 02:11:25 -0300 (ART)
Received: from mx1.descartes.web-experto.com (mx1.descartes.web-experto.com [67.205.118.17]) by panel.descartes.web-experto.com (Postfix) with ESMTP id 12D15B5C560 for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 02:11:25 -0300 (ART)
Received: from localhost (localhost [127.0.0.1]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 0524B36A09C for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:15:28 -0300 (ART)
Received: from mx1.descartes.web-experto.com ([127.0.0.1]) by localhost (mx1.descartes.web-experto.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mSTUzgijVkMB for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:15:27 -0300 (ART)
Received: from cpan.rt.develooper.com (cpan.rt.develooper.com [207.171.7.181]) by mx1.descartes.web-experto.com (Postfix) with ESMTP id 3460C36A09B for <soporte [...] web-experto.com.ar>; Thu, 25 Feb 2010 04:15:27 -0300 (ART)
Received: by cpan.rt.develooper.com (Postfix, from userid 536) id 5A0B5704D; Thu, 25 Feb 2010 01:04:34 -0800 (PST)
Subject: [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [Autoreply] [rt.cpan.org #54949] Search with has_many relation fails at using ORDER BY RAND()
X-Original-To: macevedo [...] web-experto.com.ar
Date: Thu, 25 Feb 2010 04:04:34 -0500
RT-Ticket: rt.cpan.org #54949
Precedence: normal
To: soporte [...] web-experto.com.ar
X-RT-Loop-Prevention: rt.cpan.org
From: "macevedo via RT" <bug-DBIx-Class [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381938
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381939
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381940
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381941
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381942
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381943
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381944
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381945
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381946
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381947
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381948
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381949
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381950
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381951
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381952
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 237
Download (untitled) / with headers
text/plain 237b
<URL: http://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381953
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381954
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 238
Download (untitled) / with headers
text/plain 238b
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > En este momento me encuentro de vacaciones, por favor comunicarse al 527-1070 o enviar el email a soporte@web-experto.com.ar Saludo Atte. Martín Acevedo - Atención al cliente
RT-Attachment: 54949/739014/381955
Content-Type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 5611
Download (untitled) / with headers
text/plain 5.4k
<URL: https://rt.cpan.org/Ticket/Display.html?id=54949 > On Wed Feb 24 15:24:56 2010, webexperto wrote: Show quoted text
> Hi, first i apologies about my english, i will try to express my self > the best i can. I found this issue that i detail next. Thanks > > DBIx-Class: DBIx-Class-0.08119 > Perl Version: 5.8 > OS: Ubuntu 8.10 > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > use strict; > use warnings; > use base qw/DBIx::Class/; > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > __PACKAGE__->table('catalogue_products'); > __PACKAGE__->add_columns(qw/id_product id_node name_product > description_product is_actived_product datetime_added_product > datetime_last_modified_product date_start_publish_product > date_finish_publish_product imagen_product resumen_product > codigo_product destacado_product oferta_product skin_name/); > __PACKAGE__->set_primary_key(qw/ id_product /); > __PACKAGE__->has_many( > 'productPrice' => > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > {'foreign.idProduct' => 'self.id_product'}, > {cascade_delete => 0}, > ); > __PACKAGE__->has_one( > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > {'foreign.id' => 'self.id_node'}, > {cascade_delete => 0}, > ); > 1; > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > use strict; > use warnings; > use base qw/DBIx::Class/; > __PACKAGE__->load_components(qw/PK::Auto Core/); > __PACKAGE__->table('catalogue_productPrices'); > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > __PACKAGE__->set_primary_key(qw/ id /); > __PACKAGE__->has_one( > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > {'foreign.id' => 'self.idCurrency' }, > ); > > __PACKAGE__->belongs_to( > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > {'foreign.id' => 'self.idPriceList' }, > ); > 1; > > > > #CODE > my @productPrefetch; > push(@productPrefetch,'node'); > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > my $searchAttributes = { > prefetch => \@productPrefetch, > rows => 3, > order_by=> 'RAND()', #<-- cause the bug > group_by => 'me.id_product', > }; > my $rsProducts = $schema->resultset('Product')->search({}, > $searchAttributes); > my $totalItems = $rsProducts->pager()->total_entries; > > > > What i expect is a set of products with has_many relation (productPrice) > loaded with all prices. What i get is three products but eachone repeted > 3 times, > seems that group_by is not working. > > Sql query looks like this: > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > productPrice.idProduct, productPrice.idPriceList, > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > currency.symbol FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, me.is_actived_product, > me.datetime_added_product, me.datetime_last_modified_product, > me.date_start_publish_product, me.date_finish_publish_product, > me.imagen_product, me.resumen_product, me.codigo_product, > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > The last 'ORDER BY RAND()' mix up the product results (its seems like > group_by is ignored). If you dont specify order_by attribute (with > 'RAND()') its works just fine. > > If you need more details please let me know. Thanks again.
First of all this has nothing to do with GROUP BY (which is espected in the innermost select). In order to resolve this bug on the technical level, I need a proposal for SQL that *will* work in this situation. From all I know it is simply not possible to express what you want in pure SQL because: 1) All rows relevant to the same catalogue_product need to be grouped together (appear one after another). For this the order_by criteria for the outermost select *must* be "by PK/Unique column(s) of catalogue_product. This requirement is necessary to make ->next work (we fetch rows until the master-PK changes) 2) You want a random ordering of rows which is in direct contradiction with the above requirement. You either: 2a) Make the outermost select ordered by your criteria, which messes up the sequencin of different catalogue_products an gies you the result you observe 2b) Make the inner catalogue_product-only select ordered by your criteria - the outer order_by will reorder the results of the join again 2c) Make the inner catalogue_product-only select ordered by your desired criteria and DO NOT order the outermost join result - this will result in non-deterministic order of the final result, depending on how the rows are atually stored in the database. So there - 3 scenarios I can think of, none of which really work. If you can express it in *deterministic* SQL - I can make DBIC execute it, no questions asked. Cheers
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-14818-1267087489-480.54949-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
References: <rt-3.8.HEAD-14818-1267087489-480.54949-0-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1267105045-14831-257"
Message-ID: <rt-3.8.HEAD-14831-1267105045-797.54949-0-0 [...] rt.cpan.org>
From: soporte [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 6595
Download (untitled) / with headers
text/plain 6.4k
El Jue feb 25 03:44:49 2010, RIBASUSHI escribió: Show quoted text
> On Wed Feb 24 15:24:56 2010, webexperto wrote:
> > Hi, first i apologies about my english, i will try to express my self > > the best i can. I found this issue that i detail next. Thanks > > > > DBIx-Class: DBIx-Class-0.08119 > > Perl Version: 5.8 > > OS: Ubuntu 8.10 > > > > package WEBEXPERTO::Modulos::Catalogue::Model::Product; > > use strict; > > use warnings; > > use base qw/DBIx::Class/; > > use base qw/WEBEXPERTO::Core::MEB::Model::Model/; > > __PACKAGE__->load_components(qw/PK::Auto ResultSetManager Core/); > > __PACKAGE__->table('catalogue_products'); > > __PACKAGE__->add_columns(qw/id_product id_node name_product > > description_product is_actived_product datetime_added_product > > datetime_last_modified_product date_start_publish_product > > date_finish_publish_product imagen_product resumen_product > > codigo_product destacado_product oferta_product skin_name/); > > __PACKAGE__->set_primary_key(qw/ id_product /); > > __PACKAGE__->has_many( > > 'productPrice' => > > 'WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice', > > {'foreign.idProduct' => 'self.id_product'}, > > {cascade_delete => 0}, > > ); > > __PACKAGE__->has_one( > > 'node' => 'WEBEXPERTO::Modulos::Catalogue::Model::Node', > > {'foreign.id' => 'self.id_node'}, > > {cascade_delete => 0}, > > ); > > 1; > > > > package WEBEXPERTO::Modulos::Catalogue::Model::ProductPrice; > > use strict; > > use warnings; > > use base qw/DBIx::Class/; > > __PACKAGE__->load_components(qw/PK::Auto Core/); > > __PACKAGE__->table('catalogue_productPrices'); > > __PACKAGE__->add_columns(qw/id idProduct idPriceList idCurrency value/); > > __PACKAGE__->set_primary_key(qw/ id /); > > __PACKAGE__->has_one( > > 'currency' =>'WEBEXPERTO::Modulos::Catalogue::Model::Currency', > > {'foreign.id' => 'self.idCurrency' }, > > ); > > > > __PACKAGE__->belongs_to( > > 'priceList' =>'WEBEXPERTO::Modulos::Catalogue::Model::PriceList', > > {'foreign.id' => 'self.idPriceList' }, > > ); > > 1; > > > > > > > > #CODE > > my @productPrefetch; > > push(@productPrefetch,'node'); > > push(@productPrefetch,{'productPrice'=>'currency'});#has_many relation > > my $searchAttributes = { > > prefetch => \@productPrefetch, > > rows => 3, > > order_by=> 'RAND()', #<-- cause the bug > > group_by => 'me.id_product', > > }; > > my $rsProducts = $schema->resultset('Product')->search({}, > > $searchAttributes); > > my $totalItems = $rsProducts->pager()->total_entries; > > > > > > > > What i expect is a set of products with has_many relation (productPrice) > > loaded with all prices. What i get is three products but eachone repeted > > 3 times, > > seems that group_by is not working. > > > > Sql query looks like this: > > SELECT me.id_product, me.id_node, me.name_product, > > me.description_product, me.is_actived_product, > > me.datetime_added_product, me.datetime_last_modified_product, > > me.date_start_publish_product, me.date_finish_publish_product, > > me.imagen_product, me.resumen_product, me.codigo_product, > > me.destacado_product, me.oferta_product, me.skin_name, productPrice.id, > > productPrice.idProduct, productPrice.idPriceList, > > productPrice.idCurrency, productPrice.value, currency.id, currency.name, > > currency.symbol FROM > > (SELECT me.id_product, me.id_node, me.name_product, > > me.description_product, me.is_actived_product, > > me.datetime_added_product, me.datetime_last_modified_product, > > me.date_start_publish_product, me.date_finish_publish_product, > > me.imagen_product, me.resumen_product, me.codigo_product, > > me.destacado_product, me.oferta_product, me.skin_name, me.stock_product, > > me.iva_product, me.marca_product FROM catalogue_products me GROUP BY > > me.id_product ORDER BY RAND() LIMIT 3) me > > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > > productPrice.idCurrency ORDER BY RAND(), productPrice.idProduct; > > > > The last 'ORDER BY RAND()' mix up the product results (its seems like > > group_by is ignored). If you dont specify order_by attribute (with > > 'RAND()') its works just fine. > > > > If you need more details please let me know. Thanks again.
> > First of all this has nothing to do with GROUP BY (which is espected in > the innermost select). > > In order to resolve this bug on the technical level, I need a proposal > for SQL that *will* work in this situation. From all I know it is simply > not possible to express what you want in pure SQL because: > > 1) All rows relevant to the same catalogue_product need to be grouped > together (appear one after another). For this the order_by criteria for > the outermost select *must* be "by PK/Unique column(s) of > catalogue_product. This requirement is necessary to make ->next work (we > fetch rows until the master-PK changes) > > 2) You want a random ordering of rows which is in direct contradiction > with the above requirement. You either: > > 2a) Make the outermost select ordered by your criteria, which messes up > the sequencin of different catalogue_products an gies you the result you > observe > > 2b) Make the inner catalogue_product-only select ordered by your > criteria - the outer order_by will reorder the results of the join again > > 2c) Make the inner catalogue_product-only select ordered by your desired > criteria and DO NOT order the outermost join result - this will result > in non-deterministic order of the final result, depending on how the > rows are atually stored in the database. > > So there - 3 scenarios I can think of, none of which really work. If you > can express it in *deterministic* SQL - I can make DBIC execute it, no > questions asked. > > Cheers
Thanks for replay, the SQL i excpect looks like this: SELECT me.id_product, me.id_node, me.name_product, me.description_product, ........ FROM (SELECT me.id_product, me.id_node, me.name_product, me.description_product, ...... FROM catalogue_products me GROUP BY me.id_product ORDER BY RAND() LIMIT 3) me LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = productPrice.idCurrency ORDER BY productPrice.idProduct; Its the same as last sql query, but in the outer select i remove RAND() ordering (see attached files). The innermost select is ok. is there any way that dbix keep order_by off from outer select? Thank you!
Subject: outer_select_without_rand.jpeg
MIME-Version: 1.0
Content-Type: image/jpeg; name="outer_select_without_rand.jpeg"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline; filename="outer_select_without_rand.jpeg"
Content-Transfer-Encoding: base64
Content-Length: 154154
outer_select_without_rand.jpeg
MIME-Version: 1.0
Subject: outer_select_with_rand.jpeg
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: image/jpeg; name="outer_select_with_rand.jpeg"
Content-Disposition: inline; filename="outer_select_with_rand.jpeg"
Content-Transfer-Encoding: base64
Content-Length: 181470
outer_select_with_rand.jpeg
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-14831-1267105045-797.54949-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-14818-1267087489-480.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14831-1267105045-797.54949-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-14813-1267109534-589.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 953
Download (untitled) / with headers
text/plain 953b
Show quoted text
> Thanks for replay, the SQL i excpect looks like this: > > SELECT me.id_product, me.id_node, me.name_product, > me.description_product, ........ FROM > (SELECT me.id_product, me.id_node, me.name_product, > me.description_product, ...... FROM catalogue_products me GROUP BY > me.id_product ORDER BY RAND() LIMIT 3) me > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > productPrice.idCurrency ORDER BY productPrice.idProduct; > > Its the same as last sql query, but in the outer select i remove RAND() > ordering (see attached files). The innermost select is ok. > is there any way that dbix keep order_by off from outer select?
This SQL will never return random results, you can run it as many times as you like, the final set will be ordered by productPrice.idProduct Or was your objective only to get 3 random rows with their stuff prefetched?
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-14813-1267109534-589.54949-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-14818-1267087489-480.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14831-1267105045-797.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14813-1267109534-589.54949-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-14816-1267113039-969.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: soporte [...] web-experto.com.ar
X-RT-Original-Encoding: utf-8
Content-Length: 1464
Download (untitled) / with headers
text/plain 1.4k
El Jue feb 25 09:52:14 2010, RIBASUSHI escribió: Show quoted text
> > Thanks for replay, the SQL i excpect looks like this: > > > > SELECT me.id_product, me.id_node, me.name_product, > > me.description_product, ........ FROM > > (SELECT me.id_product, me.id_node, me.name_product, > > me.description_product, ...... FROM catalogue_products me GROUP BY > > me.id_product ORDER BY RAND() LIMIT 3) me > > LEFT JOIN catalogue_productPrices productPrice ON productPrice.idProduct > > = me.id_product LEFT JOIN catalogue_currencies currency ON currency.id = > > productPrice.idCurrency ORDER BY productPrice.idProduct; > > > > Its the same as last sql query, but in the outer select i remove RAND() > > ordering (see attached files). The innermost select is ok. > > is there any way that dbix keep order_by off from outer select?
> > This SQL will never return random results, you can run it as many times > as you like, the final set will be ordered by productPrice.idProduct > > Or was your objective only to get 3 random rows with their stuff
prefetched? Yes, that was my objective! and the sql does return random, but in my opinion the final order_by should not be there, it works fine with just the innermost order_by. The final order_by is automaticaly added by DBIx-Class, it's not seted by me. And it makes rows appear not grouped by id_product, which cause a wrong prefetched. I finaly got 3 diferent random products, but in 9 product objects (they are repeted). Thanks!
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-14816-1267113039-969.54949-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-14818-1267087489-480.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14831-1267105045-797.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14813-1267109534-589.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14816-1267113039-969.54949-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-14818-1267113293-1229.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 1695
Download (untitled) / with headers
text/plain 1.6k
On Thu Feb 25 10:50:40 2010, webexperto wrote: Show quoted text
> El Jue feb 25 09:52:14 2010, RIBASUSHI escribió:
> > > Thanks for replay, the SQL i excpect looks like this: > > > > > > SELECT me.id_product, me.id_node, me.name_product, > > > me.description_product, ........ FROM > > > (SELECT me.id_product, me.id_node, me.name_product, > > > me.description_product, ...... FROM catalogue_products me GROUP BY > > > me.id_product ORDER BY RAND() LIMIT 3) me > > > LEFT JOIN catalogue_productPrices productPrice ON
productPrice.idProduct Show quoted text
> > > = me.id_product LEFT JOIN catalogue_currencies currency ON
currency.id = Show quoted text
> > > productPrice.idCurrency ORDER BY productPrice.idProduct; > > > > > > Its the same as last sql query, but in the outer select i remove
RAND() Show quoted text
> > > ordering (see attached files). The innermost select is ok. > > > is there any way that dbix keep order_by off from outer select?
> > > > This SQL will never return random results, you can run it as many times > > as you like, the final set will be ordered by productPrice.idProduct > > > > Or was your objective only to get 3 random rows with their stuff
> prefetched? > > Yes, that was my objective! and the sql does return random, but in my > opinion the final order_by should not be there, it works fine with just > the innermost order_by. The final order_by is automaticaly added by > DBIx-Class, it's not seted by me. And it makes rows appear not grouped > by id_product, which cause a wrong prefetched. > I finaly got 3 diferent random products, but in 9 product objects (they > are repeted). > Thanks!
Right... this problem is much deeper than it initially appears, work is being done to resolve it, possibly by end of week.
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-14818-1267113293-1229.54949-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-14818-1267087489-480.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14831-1267105045-797.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14813-1267109534-589.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14816-1267113039-969.54949-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-14818-1267113293-1229.54949-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-11063-1284294203-1271.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 236
Download (untitled) / with headers
text/plain 236b
Just a heads up that this bug has not been forgotten. The underlying machinery rewrite however proved quite the bitch, thus no sane ETA is currently available on when this will be finally fixed (but it definitely will be at some point).
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-17367-1328085245-142.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 91
Stalling until we solve the underlying problem in the DBIC codebase. Sorry for the delay :(
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-30927-1334670384-977.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 87
This is now fixed in the repo master: git://git.shadowcat.co.uk/dbsrgits/DBIx-Class.git
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-8233-1346347270-849.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 51
Re-stalling until parent RT#74584 is truly resolved
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-3979-1360840199-626.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 50
Hopefully this time DBIC 0.08240 nails this issue.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.11-6337-1367304572-1491.54949-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 53
And production version resolving this is now on CPAN.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.