[Bast-commits] r3426 - in branches/DBIx-Class-current: .
lib/DBIx/Class t
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Tue May 29 02:08:59 GMT 2007
Author: matthewt
Date: 2007-05-29 02:08:58 +0100 (Tue, 29 May 2007)
New Revision: 3426
Modified:
branches/DBIx-Class-current/
branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm
branches/DBIx-Class-current/t/101populate_rs.t
Log:
r51843 at cain (orig r3390): jnapiorkowski | 2007-05-28 22:42:17 +0000
Added hack to force wantarray mode if bulk insert can't complete due to missing relating keys in the data. Updated tests to reflect above.
Property changes on: branches/DBIx-Class-current
___________________________________________________________________
Name: svk:merge
- 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.bulk_create:29204
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.current:29201
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.oracle8:29250
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/bulk_create:3389
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/collapse_result_rewrite:3292
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/column_info_from_storage:2596
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/load_namespaces:2725
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/param_bind:3015
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/source-handle:2975
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/storage_exceptions:2617
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/versioning:2930
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3355
+ 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.bulk_create:29204
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.current:29201
78d5d833-3a7e-474d-aed6-cfba645156b5:/local/DBIx-Class.oracle8:29250
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/bulk_create:3390
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/collapse_result_rewrite:3292
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/column_info_from_storage:2596
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/load_namespaces:2725
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/param_bind:3015
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/source-handle:2975
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/storage_exceptions:2617
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/versioning:2930
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3355
Modified: branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm
===================================================================
--- branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm 2007-05-29 01:08:49 UTC (rev 3425)
+++ branches/DBIx-Class-current/lib/DBIx/Class/ResultSet.pm 2007-05-29 01:08:58 UTC (rev 3426)
@@ -1244,7 +1244,7 @@
=over 4
-=item Arguments: $source_name, \@data;
+=item Arguments: \@data;
=back
@@ -1280,18 +1280,18 @@
## Array Context Example
my ($ArtistOne, $ArtistTwo, $ArtistThree) = $Artist_rs->populate([
{ name => "Artist One"},
- { name => "Artist Two"},
- { name => "Artist Three", cds=> [
- { title => "First CD", year => 2007},
- { title => "Second CD", year => 2008},
- ]}
+ { name => "Artist Two"},
+ { name => "Artist Three", cds=> [
+ { title => "First CD", year => 2007},
+ { title => "Second CD", year => 2008},
+ ]}
]);
print $ArtistOne->name; ## response is 'Artist One'
print $ArtistThree->cds->count ## reponse is '2'
=cut
-use Data::Dump qw/dump/;
+
sub populate {
my ($self, $data) = @_;
@@ -1304,35 +1304,35 @@
} else {
my ($first, @rest) = @$data;
- my @names = grep {!ref $first->{$_}} keys %$first;
+ my @names = grep {!ref $first->{$_}} keys %$first;
my @rels = grep { $self->result_source->has_relationship($_) } keys %$first;
- my @pks = $self->result_source->primary_columns;
+ my @pks = $self->result_source->primary_columns;
- ## do the belongs_to relationships
- foreach my $index (0..$#{@$data})
- {
- foreach my $rel (@rels)
- {
- next unless $data->[$index]->{$rel} && ref $data->[$index]->{$rel} eq "HASH";
-
- my $result = $self->related_resultset($rel)->create($data->[$index]->{$rel});
-
- my ($reverse) = keys %{$self->result_source->reverse_relationship_info($rel)};
-
- my $related = $result->result_source->resolve_condition(
+ ## do the belongs_to relationships
+ foreach my $index (0..$#{@$data}) {
+ if( grep { !defined $data->[$index]->{$_} } @pks ) {
+ my @ret = $self->populate($data);
+ return;
+ }
+
+ foreach my $rel (@rels) {
+ next unless $data->[$index]->{$rel} && ref $data->[$index]->{$rel} eq "HASH";
+ my $result = $self->related_resultset($rel)->create($data->[$index]->{$rel});
+ my ($reverse) = keys %{$self->result_source->reverse_relationship_info($rel)};
+ my $related = $result->result_source->resolve_condition(
+ $result->result_source->relationship_info($reverse)->{cond},
+ $self,
+ $result,
+ );
- $result->result_source->relationship_info($reverse)->{cond},
- $self,
- $result,
- );
+ delete $data->[$index]->{$rel};
+ $data->[$index] = {%{$data->[$index]}, %$related};
+
+ push @names, keys %$related if $index == 0;
+ }
+ }
- delete $data->[$index]->{$rel};
- $data->[$index] = {%{$data->[$index]}, %$related};
-
- push @names, keys %$related if $index == 0;
- }
- }
-
+ ## do bulk insert on current row
my @values = map {
[ map {
defined $_ ? $_ : $self->throw_exception("Undefined value for column!")
@@ -1345,15 +1345,17 @@
\@values,
);
- ## do the has_many relationships
+ ## do the has_many relationships
foreach my $item (@$data) {
foreach my $rel (@rels) {
next unless $item->{$rel} && ref $item->{$rel} eq "ARRAY";
- my $parent = $self->find(map {{$_=>$item->{$_}} } @pks) || next;
+ my $parent = $self->find(map {{$_=>$item->{$_}} } @pks)
+ || $self->throw_exception('Cannot find the relating object.');
+
my $child = $parent->$rel;
-
+
my $related = $child->result_source->resolve_condition(
$parent->result_source->relationship_info($rel)->{cond},
$child,
Modified: branches/DBIx-Class-current/t/101populate_rs.t
===================================================================
--- branches/DBIx-Class-current/t/101populate_rs.t 2007-05-29 01:08:49 UTC (rev 3425)
+++ branches/DBIx-Class-current/t/101populate_rs.t 2007-05-29 01:08:58 UTC (rev 3426)
@@ -516,8 +516,6 @@
## changing columns
## basically errors for non well formed data
## check for the first incomplete problem
- ## can we solve the problem of void context and no PKs?
-
}
More information about the Bast-commits
mailing list