6 my @art = $schema->resultset("Artist")->search({ }, { order_by => 'name DESC'});
8 cmp_ok(@art, '==', 3, "Three artists returned");
12 is($art->name, 'We Are Goth', "Correct order too");
14 $art->name('We Are In Rehab');
16 is($art->name, 'We Are In Rehab', "Accessor update ok");
18 is($art->get_column("name"), 'We Are In Rehab', 'And via get_column');
20 ok($art->update, 'Update run');
22 @art = $schema->resultset("Artist")->search({ name => 'We Are In Rehab' });
24 cmp_ok(@art, '==', 1, "Changed artist returned by search");
26 cmp_ok($art[0]->artistid, '==', 3,'Correct artist too');
30 @art = $schema->resultset("Artist")->search({ });
32 cmp_ok(@art, '==', 2, 'And then there were two');
34 ok(!$art->in_storage, "It knows it's dead");
36 eval { $art->delete; };
38 ok($@, "Can't delete twice: $@");
40 is($art->name, 'We Are In Rehab', 'But the object is still live');
44 ok($art->in_storage, "Re-created");
46 @art = $schema->resultset("Artist")->search({ });
48 cmp_ok(@art, '==', 3, 'And now there are three again');
50 my $new = $schema->resultset("Artist")->create({ artistid => 4 });
52 cmp_ok($new->artistid, '==', 4, 'Create produced record ok');
54 @art = $schema->resultset("Artist")->search({ });
56 cmp_ok(@art, '==', 4, "Oh my god! There's four of them!");
58 $new->set_column('name' => 'Man With A Fork');
60 is($new->name, 'Man With A Fork', 'set_column ok');
62 $new->discard_changes;
64 ok(!defined $new->name, 'Discard ok');
66 $new->name('Man With A Spoon');
70 $new_again = $schema->resultset("Artist")->find(4);
72 is($new_again->name, 'Man With A Spoon', 'Retrieved correctly');
74 is($new_again->ID, 'DBICTest::Artist|artistid=4', 'unique object id generated correctly');
76 is($schema->resultset("Artist")->count, 4, 'count ok');
78 my $cd = $schema->resultset("CD")->find(1);
79 my %cols = $cd->get_columns;
81 cmp_ok(keys %cols, '==', 4, 'get_columns number of columns ok');
83 is($cols{title}, 'Spoonful of bees', 'get_columns values ok');
85 %cols = ( title => 'Forkful of bees', year => 2005);
86 $cd->set_columns(\%cols);
88 is($cd->title, 'Forkful of bees', 'set_columns ok');
90 is($cd->year, 2005, 'set_columns ok');
94 # check whether ResultSource->columns returns columns in order originally supplied
95 my @cd = $schema->source("CD")->columns;
97 is_deeply( \@cd, [qw/cdid artist title year/], 'column order');
99 $cd = $schema->resultset("CD")->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next;
100 is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly');
103 $new = $schema->resultset("Track")->new( {
107 title => 'Insert or Update',
109 $new->insert_or_update;
110 ok($new->in_storage, 'insert_or_update insert ok');
112 # test in update mode
114 $new->insert_or_update;
115 is( $schema->resultset("Track")->find(100)->position, 5, 'insert_or_update update ok');
117 eval { $schema->class("Track")->load_components('DoesNotExist'); };
121 is($schema->class("Artist")->field_name_for->{name}, 'artist name', 'mk_classdata usage ok');
123 my $search = [ { 'tags.tag' => 'Cheesy' }, { 'tags.tag' => 'Blue' } ];
125 my $or_rs = $schema->resultset("CD")->search($search, { join => 'tags',
126 order_by => 'cdid' });
128 cmp_ok($or_rs->count, '==', 5, 'Search with OR ok');
130 my $distinct_rs = $schema->resultset("CD")->search($search, { join => 'tags', distinct => 1 });
132 cmp_ok($distinct_rs->all, '==', 4, 'DISTINCT search with OR ok');
134 my $tag_rs = $schema->resultset('Tag')->search(
135 [ { 'me.tag' => 'Cheesy' }, { 'me.tag' => 'Blue' } ]);
137 my $rel_rs = $tag_rs->search_related('cd');
139 cmp_ok($rel_rs->count, '==', 5, 'Related search ok');
141 cmp_ok($or_rs->next->cdid, '==', $rel_rs->next->cdid, 'Related object ok');
144 ok($schema->storage(), 'Storage available');
146 $schema->source("Artist")->{_columns}{'artistid'} = {};
148 my $typeinfo = $schema->source("Artist")->column_info('artistid');
149 is($typeinfo->{data_type}, 'INTEGER', 'column_info ok');