[Bast-commits] r5564 - DBIx-Class/0.08/branches/subquery/t/search
michaelr at dev.catalyst.perl.org
michaelr at dev.catalyst.perl.org
Fri Feb 20 04:42:15 GMT 2009
Author: michaelr
Date: 2009-02-20 04:42:15 +0000 (Fri, 20 Feb 2009)
New Revision: 5564
Modified:
DBIx-Class/0.08/branches/subquery/t/search/subquery.t
Log:
fixed from => subquery test. added from => nested subquery test
Modified: DBIx-Class/0.08/branches/subquery/t/search/subquery.t
===================================================================
--- DBIx-Class/0.08/branches/subquery/t/search/subquery.t 2009-02-20 04:41:44 UTC (rev 5563)
+++ DBIx-Class/0.08/branches/subquery/t/search/subquery.t 2009-02-20 04:42:15 UTC (rev 5564)
@@ -10,7 +10,7 @@
use DBICTest;
use DBIC::SqlMakerTest;
-plan tests => 5;
+plan tests => 6;
my $schema = DBICTest->init_schema();
my $art_rs = $schema->resultset('Artist');
@@ -53,8 +53,8 @@
);
}
-TODO: {
- local $TODO = "'from' doesn't work with as_query yet.";
+# simple from
+{
my $rs = $cdrs->search(
{},
{
@@ -69,14 +69,13 @@
my ($query, @bind) = @{$$arr};
is_same_sql_bind(
$query, \@bind,
- "SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.artistid, me.name, me.rank, me.charfield FROM cds me WHERE id > 20) cd2",
+ "SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE id > 20) cd2",
[],
);
}
# nested from
-TODO: {
- local $TODO = "'from' doesn't work with as_query yet.";
+{
my $art_rs2 = $schema->resultset('Artist')->search({},
{
from => [ { 'me' => 'artist' },
@@ -94,7 +93,42 @@
}
+# nested subquery in from
{
+ my $rs = $cdrs->search(
+ {},
+ {
+ alias => 'cd2',
+ from => [
+ { cd2 => $cdrs->search(
+ { id => { '>' => 20 } },
+ {
+ alias => 'cd3',
+ from => [
+ { cd3 => $cdrs->search( { id => { '<' => 40 } } )->as_query }
+ ],
+ }, )->as_query },
+ ],
+ },
+ );
+
+ my $arr = $rs->as_query;
+ my ($query, @bind) = @{$$arr};
+ is_same_sql_bind(
+ $query, \@bind,
+ "SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track
+ FROM
+ (SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track
+ FROM
+ (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track
+ FROM cd me WHERE id < 40) cd3
+ WHERE id > 20) cd2",
+ [],
+ );
+
+}
+
+{
my $rs = $cdrs->search({
year => {
'=' => $cdrs->search(
More information about the Bast-commits
mailing list