use Test::More;
use Test::Exception;
use lib qw(t/lib);
-use DBICTest;
-use DBIC::SqlMakerTest;
+use DBICTest ':DiffSQL';
my $schema = DBICTest->init_schema();
-my $sdebug = $schema->storage->debug;
# has_a test
my $cd = $schema->resultset("CD")->find(4);
my $big_flop_cd = ($artist->search_related('cds'))[3];
is( $big_flop_cd->title, 'Big Flop', 'create_related ok' );
-{ # make sure we are not making pointless select queries when a FK IS NULL
- my $queries = 0;
- $schema->storage->debugcb(sub { $queries++; });
- $schema->storage->debug(1);
+# make sure we are not making pointless select queries when a FK IS NULL
+$schema->is_executed_querycount( sub {
$big_flop_cd->genre; #should not trigger a select query
- is($queries, 0, 'No SELECT made for belongs_to if key IS NULL');
+}, 0, 'No SELECT made for belongs_to if key IS NULL');
+
+$schema->is_executed_querycount( sub {
$big_flop_cd->genre_inefficient; #should trigger a select query
- is($queries, 1, 'SELECT made for belongs_to if key IS NULL when undef_on_null_fk disabled');
- $schema->storage->debug($sdebug);
- $schema->storage->debugcb(undef);
-}
+}, 1, 'SELECT made for belongs_to if key IS NULL when undef_on_null_fk disabled');
my( $rs_from_list ) = $artist->search_related_rs('cds');
isa_ok( $rs_from_list, 'DBIx::Class::ResultSet', 'search_related_rs in list context returns rs' );
my $undef_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 'badgers', 'year' => 2007 });
-is($undef_artist_cd->has_column_loaded('artist'), '', 'FK not loaded');
+ok(! $undef_artist_cd->has_column_loaded('artist'), 'FK not loaded');
is($undef_artist_cd->search_related('artist')->count, 0, '0=1 search when FK does not exist and object not yet in db');
lives_ok {
$undef_artist_cd->related_resultset('artist')->new({name => 'foo'});
$undir_maps = $schema->resultset("Artist")->find(2)->artist_undirected_maps;
is($undir_maps->count, 1, 'found 1 undirected map for artist 2');
+{
+ my $artist_to_mangle = $schema->resultset('Artist')->find(2);
+
+ $artist_to_mangle->set_from_related( artist_undirected_maps => { id1 => 42 } );
+
+ ok( ! $artist_to_mangle->is_changed, 'Unresolvable set_from_related did not alter object' );
+
+ $artist_to_mangle->set_from_related( artist_undirected_maps => {} );
+ ok( $artist_to_mangle->is_changed, 'Definitive set_from_related did alter object' );
+ is (
+ $artist_to_mangle->id,
+ undef,
+ 'Correctly unset id on definitive outcome of OR condition',
+ );
+}
+
my $mapped_rs = $undir_maps->search_related('mapped_artists');
my @art = $mapped_rs->all;