X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema.pm;h=02c48deb28ee982fc32c6479794dcefba6add17a;hb=645de9002cae758b595dccef238f15f2414ad7c0;hp=d72e3d4389990647e29e7d268363d54eb9e0cba4;hpb=829517d4c466a52cac6123bb6e56af32c76f9646;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index d72e3d4..02c48de 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -211,7 +211,6 @@ sub load_namespaces { foreach my $result (keys %results) { my $result_class = $results{$result}; $class->ensure_class_loaded($result_class); - $result_class->source_name($result) unless $result_class->source_name; my $rs_class = delete $resultsets{$result}; my $rs_set = $result_class->resultset_class; @@ -226,7 +225,9 @@ sub load_namespaces { $result_class->resultset_class($rs_class); } - push(@to_register, [ $result_class->source_name, $result_class ]); + my $source_name = $result_class->source_name || $result; + + push(@to_register, [ $source_name, $result_class ]); } } @@ -439,6 +440,13 @@ L or L. For an example of what you can do with this, see L. +Note that sqlt_deploy_hook is called by L, which in turn +is called before L. Therefore the hook can be used only to manipulate +the L object before it is turned into SQL fed to the +database. If you want to execute post-deploy statements which can not be generated +by L, the currently suggested method is to overload L +and use L. + =head1 METHODS =head2 connect @@ -456,9 +464,13 @@ is used to create a new instance of the storage backend and set it on the Schema object. See L for DBI-specific -syntax on the C>@connectinfo> argument, or L in +syntax on the C<@connectinfo> argument, or L in general. +Note that C expects an arrayref of arguments, but +C does not. C wraps it's arguments in an arrayref +before passing them to C. + =cut sub connect { shift->clone->connection(@_) } @@ -568,6 +580,14 @@ See L for more information. This interface is preferred over using the individual methods L, L, and L below. +WARNING: If you are connected with C 0> the transaction is +considered nested, and you will still need to call L to write your +changes when appropriate. You will also want to connect with C +1> to get partial rollback to work, if the storage driver for your database +supports it. + +Connecting with C 1> is recommended. + =cut sub txn_do { @@ -703,26 +723,15 @@ wantarray context if you want the PKs automatically created. sub populate { my ($self, $name, $data) = @_; - my $rs = $self->resultset($name); - my @names = @{shift(@$data)}; - if(defined wantarray) { - my @created; - foreach my $item (@$data) { - my %create; - @create{@names} = @$item; - push(@created, $rs->create(\%create)); - } - return @created; - } - my @results_to_create; - foreach my $datum (@$data) { - my %result_to_create; - foreach my $index (0..$#names) { - $result_to_create{$names[$index]} = $$datum[$index]; + if(my $rs = $self->resultset($name)) { + if(defined wantarray) { + return $rs->populate($data); + } else { + $rs->populate($data); } - push @results_to_create, \%result_to_create; + } else { + $self->throw_exception("$name is not a resultset"); } - $rs->populate(\@results_to_create); } =head2 connection @@ -1050,7 +1059,7 @@ If no arguments are passed, then the following default values are used: =item databases - ['MySQL', 'SQLite', 'PostgreSQL'] -=item version - $schema->VERSION +=item version - $schema->schema_version =item directory - './' @@ -1235,7 +1244,7 @@ sub register_extra_source { sub _register_source { my ($self, $moniker, $source, $params) = @_; - %$source = %{ $source->new( { %$source, source_name => $moniker }) }; + $source = $source->new({ %$source, source_name => $moniker }); my %reg = %{$self->source_registrations}; $reg{$moniker} = $source;