From fc227a2a597f3d0a880faa06fd78c80165b0d53b Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 24 Sep 2008 15:56:51 +0000 Subject: [PATCH] added a safer faster join using option --- lib/WebGUI/Crud.pm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Crud.pm b/lib/WebGUI/Crud.pm index 3f7094cd3..b85be6124 100644 --- a/lib/WebGUI/Crud.pm +++ b/lib/WebGUI/Crud.pm @@ -599,13 +599,20 @@ Here's an example of this structure: =head4 join -An array reference containing the tables you wish to join together, and the mechanisms to join them. Here's an example. +An array reference containing the tables you wish to join with this one, and the mechanisms to join them. Here's an example. [ - "anotherTable using (someId)", "yetAnotherTable on yetAnotherTable.this = anotherTable.that", ] +=head4 joinUsing + +An array reference of hash references containing the tables you wish to join with this one and the field to use to join. + + [ + {"someTable" => "thisId"}, + ] + =head4 limit Either an integer representing the number of records to return, or an array reference of an integer of the starting record position and another integer representing the number of records to return. @@ -638,6 +645,12 @@ sub getAllSql { # process joins my @joins; + if (exists $options->{joinUsing}) { + foreach my $joint (@{$options->{joinUsing}}) { + my ($table) = keys %{$joint}; + push @joins, " left join ".$dbh->quote_identifier($table)." using (".$dbh->quote_identifier($joint->{$table}).")"; + } + } if (exists $options->{join}) { foreach my $thejoin (@{$options->{join}}) { push @joins, " left join ".$thejoin;