5 my @art = DBICTest->class("Artist")->search({ }, { order_by => 'name DESC'});
7 cmp_ok(@art, '==', 3, "Three artists returned");
11 is($art->name, 'We Are Goth', "Correct order too");
13 $art->name('We Are In Rehab');
15 is($art->name, 'We Are In Rehab', "Accessor update ok");
17 is($art->get_column("name"), 'We Are In Rehab', 'And via get_column');
19 ok($art->update, 'Update run');
21 @art = DBICTest->class("Artist")->search({ name => 'We Are In Rehab' });
23 cmp_ok(@art, '==', 1, "Changed artist returned by search");
25 cmp_ok($art[0]->artistid, '==', 3,'Correct artist too');
29 @art = DBICTest->class("Artist")->search({ });
31 cmp_ok(@art, '==', 2, 'And then there were two');
33 ok(!$art->in_storage, "It knows it's dead");
35 eval { $art->delete; };
37 ok($@, "Can't delete twice: $@");
39 is($art->name, 'We Are In Rehab', 'But the object is still live');
43 ok($art->in_storage, "Re-created");
45 @art = DBICTest->class("Artist")->search({ });
47 cmp_ok(@art, '==', 3, 'And now there are three again');
49 my $new = DBICTest->class("Artist")->create({ artistid => 4 });
51 cmp_ok($new->artistid, '==', 4, 'Create produced record ok');
53 @art = DBICTest->class("Artist")->search({ });
55 cmp_ok(@art, '==', 4, "Oh my god! There's four of them!");
57 $new->set_column('name' => 'Man With A Fork');
59 is($new->name, 'Man With A Fork', 'set_column ok');
61 $new->discard_changes;
63 ok(!defined $new->name, 'Discard ok');
65 $new->name('Man With A Spoon');
69 $new_again = DBICTest->class("Artist")->find(4);
71 is($new_again->name, 'Man With A Spoon', 'Retrieved correctly');
73 is($new_again->ID, 'DBICTest::Artist|artistid=4', 'unique object id generated correctly');
75 is(DBICTest->class("Artist")->count, 4, 'count ok');
77 my $cd = DBICTest->class("CD")->find(1);
78 my %cols = $cd->get_columns;
80 cmp_ok(keys %cols, '==', 4, 'get_columns number of columns ok');
82 is($cols{title}, 'Spoonful of bees', 'get_columns values ok');
84 %cols = ( title => 'Forkful of bees', year => 2005);
85 $cd->set_columns(\%cols);
87 is($cd->title, 'Forkful of bees', 'set_columns ok');
89 is($cd->year, 2005, 'set_columns ok');
93 $cd = DBICTest->class("CD")->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next;
94 is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly');
97 $new = DBICTest->class("Track")->new( {
101 title => 'Insert or Update',
103 $new->insert_or_update;
104 ok($new->in_storage, 'insert_or_update insert ok');
106 # test in update mode
108 $new->insert_or_update;
109 is( DBICTest->class("Track")->find(100)->position, 5, 'insert_or_update update ok');
111 eval { DBICTest->class("Track")->load_components('DoesNotExist'); };
115 is(DBICTest->class("Artist")->field_name_for->{name}, 'artist name', 'mk_classdata usage ok');
117 my $search = [ { 'tags.tag' => 'Cheesy' }, { 'tags.tag' => 'Blue' } ];
119 my $or_rs = DBICTest->class("CD")->search($search, { join => 'tags',
120 order_by => 'cdid' });
122 cmp_ok($or_rs->count, '==', 5, 'Search with OR ok');
124 my $distinct_rs = DBICTest->class("CD")->search($search, { join => 'tags', distinct => 1 });
126 cmp_ok($distinct_rs->all, '==', 4, 'DISTINCT search with OR ok');
128 my $tag_rs = DBICTest->class('Tag')->search(
129 [ { 'me.tag' => 'Cheesy' }, { 'me.tag' => 'Blue' } ]);
131 my $rel_rs = $tag_rs->search_related('cd');
133 cmp_ok($rel_rs->count, '==', 5, 'Related search ok');
135 cmp_ok($or_rs->next->cdid, '==', $rel_rs->next->cdid, 'Related object ok');