8 my $schema = DBICTest->init_schema();
11 # test with relname == colname
12 my $bookmark = $schema->resultset("Bookmark")->find(1);
13 ok( $bookmark->has_column ('link'), 'Right column name' );
14 ok( $bookmark->has_relationship ('link'), 'Right rel name' );
16 my $link = $bookmark->link;
18 my $new_link = $schema->resultset("Link")->create({
19 url => "http://bugsarereal.com",
20 title => "bugsarereal.com",
24 is( $bookmark->link->id, 1, 'Initial relation id' );
26 $bookmark->set_column( 'link', 9 );
27 is( $bookmark->link->id, 9, 'Correct object re-selected after belongs_to set' );
29 $bookmark->discard_changes;
30 is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
33 $bookmark->link($new_link);
34 is( $bookmark->get_column('link'), 9, 'Correct column set from related' );
36 $bookmark->discard_changes;
37 is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
41 is( $bookmark->link->id, 9, 'Correct object selected on deflated accessor set');
43 $bookmark->discard_changes;
44 is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
47 $bookmark->update({ link => 9 });
48 is( $bookmark->link->id, 9, 'Correct relationship after update' );
49 is( $bookmark->get_from_storage->link->id, 9, 'Correct relationship after re-select' );
52 # test with relname != colname
53 my $lyric = $schema->resultset('Lyrics')->create({ track_id => 5 });
54 is( $lyric->track->id, 5, 'Initial relation id');
57 my $track6 = $lyric->track;
58 is( $track6->trackid, 6, 'Correct object re-selected after belongs_to set');
60 $lyric->discard_changes;
61 is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset');
63 $lyric->track($track6);
64 is( $lyric->track_id, 6, 'Correct column set from related');
66 $lyric->discard_changes;
67 is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset');
69 $lyric->update({ track => $track6 });
70 is( $lyric->track->trackid, 6, 'Correct relationship obj after update' );
71 is( $lyric->get_from_storage->track->trackid, 6, 'Correct relationship after re-select' );