_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;
# 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
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);
}
directory => 't/var/fixtures'
});
- $schema = DBICTest->init_schema(no_deploy => 1);
+ $schema = DBICTest->init_schema( no_deploy => 1);
my $fixture_dir = dir('t/var/fixtures');
foreach my $class ($schema->sources) {
}
}
}
+
+# use_create => 1
+$schema = DBICTest->init_schema();
+$fixtures = DBIx::Class::Fixtures->new({
+ config_dir => $config_dir,
+ debug => 0
+});
+ok( $fixtures->dump({
+ config => "use_create.json",
+ schema => $schema,
+ directory => 't/var/fixtures'
+ }), "use_create dump executed okay"
+);
+$schema = DBICTest->init_schema( no_populate => 1 );
+$fixtures->populate({
+ directory => 't/var/fixtures',
+ connection_details => ['dbi:SQLite:t/var/DBIxClass.db', '', ''],
+ schema => $schema,
+ no_deploy => 1,
+ use_create => 1
+});
+$schema = DBICTest->init_schema( no_deploy => 1, no_populate => 1 );
+is( $schema->resultset( "Artist" )->find({ artistid => 4 })->name, "Test Name", "use_create => 1 ok" );
[ 1, 'Caterwauler McCrae' ],
[ 2, 'Random Boy Band' ],
[ 3, 'We Are Goth' ],
+ [ 4, '' ] # Test overridden new will default name to "Test Name" using use_create => 1.
]);
$schema->populate('CD', [
{ order_by => 'year' },
);
+sub new {
+ my ( $class, $args ) = @_;
+
+ $args->{name} = "Test Name" unless $args->{name};
+
+ return $class->next::method( $args );
+}
+
1;
--- /dev/null
+{
+ "sets": [{
+ "class": "Artist",
+ "ids": ["4"],
+ }]
+}