1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
use strict;
use warnings;
use Test::More;
use DBIx::Class::ResultSet::RecursiveUpdate;
use lib 't/lib';
use DBSchema;
my $schema = DBSchema->get_test_schema();
# OK, create podcast that belongs_to owner
my $podcast = $schema->resultset('Podcast')->create({
title => 'Pirates of the Caribbean',
owner => {name => 'Bob'} });
is( $podcast->title, 'Pirates of the Caribbean', 'podcast name is correct');
is( $podcast->owner->name, 'Bob', 'owner is correct' );
my $owner = $podcast->owner;
# FAIL: trying to update podcast: set owner to NULL
DBIx::Class::ResultSet::RecursiveUpdate::Functions::recursive_update(
resultset => $schema->resultset('Podcast'),
updates => {
title => 'Pirates of the Caribbean II',
owner => undef
},
object => $podcast );
$podcast->discard_changes;
# OK, title updated correctly
is( $podcast->title, 'Pirates of the Caribbean II', 'podcast name is correct');
ok( ! $podcast->owner, 'no podcast owner');
# clear db
$podcast->delete;
$owner->delete;
done_testing;
|