File: twopk_has_many.t

package info (click to toggle)
libdbix-class-resultset-recursiveupdate-perl 0.45-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,060 kB
  • sloc: perl: 5,130; sql: 640; makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download | duplicates (4)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use strict;
use warnings;

use lib 't/lib';
use Test::More;
use Test::Exception;


use_ok 'TwoPkHasManyDB::Schema';

my $schema = TwoPkHasManyDB::Schema->connect('dbi:SQLite:dbname=:memory:');

isa_ok $schema, 'DBIx::Class::Schema';

lives_ok( sub{
	$schema->deploy();
	$schema->populate('Item', [
		[ qw/id/ ],
		[ 1 ],
	]);
	$schema->populate('RelatedItem', [
		[ qw/id item_id/ ],
		[ 1, 1 ],
		[ 2, 1 ],
	]);
	$schema->populate('RelatedItem2', [
		[ qw/idcol item_id/ ],
		[ 1, 1 ],
		[ 2, 1 ],
	]);
}, 'creating and populating test database'
);

is($schema->resultset('Item')->find({ id =>1})->relateditems->count, 2);
is($schema->resultset('Item')->find({ id =>1})->relateditems2->count, 2);

# this one will fail for unpatched RecursiveUpdate
lives_ok(sub{
	$schema->resultset('Item')->recursive_update({
		id => 1,
		relateditems => [{
			id => 1,
			item_id => 1,
		}],
	});
}, "updating two_pk relation with colname id");

# this works fine, even with unpatched RecursiveUpdate
lives_ok(sub{
	$schema->resultset('Item')->recursive_update({
		id => 1,
		relateditems2 => [{
			idcol => 1,
			item_id => 1,
		}],
	});
}, "updating two_pk relation without colname id");

is($schema->resultset('Item')->find({ id =>1})->relateditems->count, 1);
is($schema->resultset('Item')->find({ id =>1})->relateditems2->count, 1);

done_testing;