Revision history for DBIx-Class-Fixtures
+1.001005
+- Fixed problem where rules containing an override of has_many weren't applied
+ correctly.
+
1.001004
- Fixed problem where descending a has_many to something with two belongs_to
relationships wouldn't get the second belongs_to.
=head1 VERSION
-Version 1.001004
+Version 1.001005
=cut
$config->{rules} ||= {};
my @sources = sort { $a->{class} cmp $b->{class} } @{delete $config->{sets}};
+ while ( my ($k,$v) = each %{ $config->{rules} } ) {
+ if ( my $rs = $schema->resultset($k) ) {
+ $config->{rules}{$rs->result_source->source_name} = $v;
+ }
+ }
+
foreach my $source (@sources) {
# apply rule to set if specified
my $rule = $config->{rules}->{$source->{class}};
# don't bother looking at rels unless we are actually planning to dump at least one type
my ($might_have, $belongs_to, $has_many) = map {
- $set->{$_}{fetch};
+ $set->{$_}{fetch} || $set->{rules}{$src->source_name}{$_}{fetch}
} qw/might_have belongs_to has_many/;
return unless $might_have
--- /dev/null
+#!perl
+
+use DBIx::Class::Fixtures;
+use Test::More tests => 11;
+use lib qw(t/lib);
+use DBICTest;
+use Path::Class;
+use Data::Dumper;
+
+# set up and populate schema
+ok(my $schema = DBICTest->init_schema(), 'got schema');
+
+my $config_dir = 't/var/configs';
+
+# do dump
+ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
+ok($fixtures->dump({ config => 'rules2.json', schema => $schema, directory => 't/var/fixtures' }), 'quantity dump executed okay');
+
+# check dump is okay
+foreach my $test (
+ [ 'artist', 1, 'Artist', 'artistid' ],
+ [ 'cd', 2, 'CD', 'cdid' ],
+) {
+ my ($dirname, $count, $moniker, $id) = @$test;
+ my $dir = dir("t/var/fixtures/$dirname");
+ my @children = $dir->children;
+ is(scalar(@children), $count, "right number of $dirname fixtures created");
+
+ foreach my $fix_file (@children) {
+ my $HASH1; eval($fix_file->slurp());
+ is(ref $HASH1, 'HASH', 'fixture evals into hash');
+ my $obj = $schema->resultset($moniker)->find($HASH1->{$id});
+ is_deeply({$obj->get_columns}, $HASH1, "dumped fixture is equivalent to $dirname row");
+ }
+}
+