X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FFixtures.pm;h=4f995b9893f8e842b79bcc68f7d97cbd9832ab1e;hb=47a8ceb927de1d34efb41834e89dd6020a0d3191;hp=2d244b60da4d228526d0db97fa3f1f7f98636d45;hpb=9b7171c7dae0ec52ad443a9b948d0874845c40ec;p=dbsrgits%2FDBIx-Class-Fixtures.git diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index 2d244b6..4f995b9 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -26,11 +26,11 @@ __PACKAGE__->mk_group_accessors( 'simple' => qw/config_dir =head1 VERSION -Version 1.001008 +Version 1.001010 =cut -our $VERSION = '1.001008'; +our $VERSION = '1.001010'; =head1 NAME @@ -425,7 +425,8 @@ sub new { _inherited_attributes => [qw/datetime_relative might_have rules belongs_to/], debug => $params->{debug} || 0, ignore_sql_errors => $params->{ignore_sql_errors}, - dumped_objects => {} + dumped_objects => {}, + use_create => $params->{use_create} || 0 }; bless $self, $class; @@ -483,6 +484,10 @@ sub dump { } } + if($params->{excludes} && !$params->{all}) { + return DBIx::Class::Exception->throw("'excludes' param only works when using the 'all' param"); + } + my $schema = $params->{schema}; my $config; if ($params->{config}) { @@ -490,11 +495,17 @@ sub dump { my $config_file = $self->config_dir->file($params->{config}); $config = $self->load_config_file($config_file); } elsif ($params->{all}) { + my %excludes = map {$_=>1} @{$params->{excludes}||[]}; $config = { might_have => { fetch => 0 }, has_many => { fetch => 0 }, belongs_to => { fetch => 0 }, - sets => [map {{ class => $_, quantity => 'all' }} $schema->sources] + sets => [ + map { + { class => $_, quantity => 'all' }; + } grep { + !$excludes{$_} + } $schema->sources], }; } else { DBIx::Class::Exception->throw('must pass config or set all'); @@ -932,6 +943,11 @@ sub _read_sql { # optional, set to 1 to run ddl but not populate no_populate => 0, + # optional, set to 1 to run each fixture through ->create rather than have + # each $rs populated using $rs->populate. Useful if you have overridden new() logic + # that effects the value of column(s). + use_create => 0, + # Dont try to clean the database, just populate over whats there. Requires # schema option. Use this if you want to handle removing old data yourself # no_deploy => 1 @@ -1059,7 +1075,11 @@ sub populate { my $HASH1; eval($contents); $HASH1 = $fixup_visitor->visit($HASH1) if $fixup_visitor; - push(@rows, $HASH1); + if ( $params->{use_create} ) { + $rs->create( $HASH1 ); + } else { + push(@rows, $HASH1); + } } $rs->populate(\@rows) if scalar(@rows); }