## Tests for the $resultset->populate method.
##
## GOALS: We need to test the method for both void and array context for all
-## the following relationship types: belongs_to, has_many. Additionally we
+## the following relationship types: refers_to, has_many. Additionally we
## need to test each of those for both specified PK's and autogenerated PK's
##
## Also need to test some stuff that should generate errors.
BELONGS_TO_NO_PKs: {
- ## Test from a belongs_to perspective, should create artist first,
+ ## Test from a refers_to perspective, should create artist first,
## then CD with artistid. This test we let the system automatically
## create the PK's. Chances are good you'll use it this way mostly.
BELONGS_TO_WITH_PKs: {
- ## Test from a belongs_to perspective, should create artist first,
+ ## Test from a refers_to perspective, should create artist first,
## then CD with artistid. This time we try setting the PK's
my $aid = $art_rs->get_column('artistid')->max || 0;
BELONGS_TO_WITH_PKs: {
- ## Test from a belongs_to perspective, should create artist first,
+ ## Test from a refers_to perspective, should create artist first,
## then CD with artistid. This time we try setting the PK's
my $aid = $art_rs->get_column('artistid')->max || 0;
BELONGS_TO_NO_PKs: {
- ## Test from a belongs_to perspective, should create artist first,
+ ## Test from a refers_to perspective, should create artist first,
## then CD with artistid.
my $cds = [
data_type => 'integer',
},
);
- __PACKAGE__->belongs_to('foo' => 'DBICTest::Schema::Foo${suffix}');
- __PACKAGE__->belongs_to('bar' => 'DBICTest::Schema::Foo${suffix}');
+ __PACKAGE__->refers_to('foo' => 'DBICTest::Schema::Foo${suffix}');
+ __PACKAGE__->refers_to('bar' => 'DBICTest::Schema::Foo${suffix}');
}
{
package #
is ($_->count, 2, 'Prefetched grouped search returns correct count');
}
- # try a ->belongs_to direction (no select collapse)
+ # try a ->refers_to direction (no select collapse)
my $books = $schema->resultset ('BooksInLibrary')->search (
{ 'owner.name' => 'wiggle' },
{ prefetch => 'owner', distinct => 1 }
{ 'foreign.parentid' => 'self.artistid' }
);
- DBICTest::Schema::Artist->belongs_to(
+ DBICTest::Schema::Artist->refers_to(
parent => 'DBICTest::Schema::Artist',
{ 'foreign.artistid' => 'self.parentid' }
);
}
- # try a ->belongs_to direction (no select collapse, group_by should work)
+ # try a ->refers_to direction (no select collapse, group_by should work)
my $books = $schema->resultset ('BooksInLibrary')->search (
{
'owner.name' => [qw/wiggle woggle/],
if (not ref ($datahashref->{$col}) ) {
is ($datahashref->{$col}, $dbic_obj->get_column($col), 'same value');
}
- # related table entry (belongs_to)
+ # related table entry (refers_to)
elsif (ref ($datahashref->{$col}) eq 'HASH') {
check_cols_of($dbic_obj->$col, $datahashref->{$col});
}
);
__PACKAGE__->set_primary_key(qw/id1 id2/);
-__PACKAGE__->belongs_to( 'artist1', 'DBICTest::Schema::Artist', 'id1', { on_delete => 'RESTRICT', on_update => 'CASCADE'} );
-__PACKAGE__->belongs_to( 'artist2', 'DBICTest::Schema::Artist', 'id2', { on_delete => undef, on_update => undef} );
+__PACKAGE__->refers_to( 'artist1', 'DBICTest::Schema::Artist', 'id1', { on_delete => 'RESTRICT', on_update => 'CASCADE'} );
+__PACKAGE__->refers_to( 'artist2', 'DBICTest::Schema::Artist', 'id2', { on_delete => undef, on_update => undef} );
__PACKAGE__->has_many(
'mapped_artists', 'DBICTest::Schema::Artist',
[ {'foreign.artistid' => 'self.id1'}, {'foreign.artistid' => 'self.id2'} ],
},
);
__PACKAGE__->set_primary_key('cd_id');
-__PACKAGE__->belongs_to('cd', 'DBICTest::Schema::CD', 'cd_id');
+__PACKAGE__->refers_to('cd', 'DBICTest::Schema::CD', 'cd_id');
__PACKAGE__->has_many('images', 'DBICTest::Schema::Image', 'artwork_id');
__PACKAGE__->has_many('artwork_to_artist', 'DBICTest::Schema::Artwork_to_Artist', 'artwork_cd_id');
},
);
__PACKAGE__->set_primary_key(qw/artwork_cd_id artist_id/);
-__PACKAGE__->belongs_to('artwork', 'DBICTest::Schema::Artwork', 'artwork_cd_id');
-__PACKAGE__->belongs_to('artist', 'DBICTest::Schema::Artist', 'artist_id');
+__PACKAGE__->refers_to('artwork', 'DBICTest::Schema::Artwork', 'artwork_cd_id');
+__PACKAGE__->refers_to('artist', 'DBICTest::Schema::Artist', 'artist_id');
-__PACKAGE__->belongs_to('artist_test_m2m', 'DBICTest::Schema::Artist',
+__PACKAGE__->refers_to('artist_test_m2m', 'DBICTest::Schema::Artist',
sub {
my $args = shift;
}
);
-__PACKAGE__->belongs_to('artist_test_m2m_noopt', 'DBICTest::Schema::Artist',
+__PACKAGE__->refers_to('artist_test_m2m_noopt', 'DBICTest::Schema::Artist',
sub {
my $args = shift;
__PACKAGE__->set_primary_key('id');
require DBICTest::Schema::Link; # so we can get a columnlist
-__PACKAGE__->belongs_to(
+__PACKAGE__->refers_to(
link => 'DBICTest::Schema::Link', 'link', {
on_delete => 'SET NULL',
join_type => 'LEFT',
__PACKAGE__->resultset_attributes({where => { source => "Library" } });
-__PACKAGE__->belongs_to ( owner => 'DBICTest::Schema::Owners', 'owner' );
+__PACKAGE__->refers_to ( owner => 'DBICTest::Schema::Owners', 'owner' );
1;
__PACKAGE__->set_primary_key('cdid');
__PACKAGE__->add_unique_constraint([ qw/artist title/ ]);
-__PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist', undef, {
+__PACKAGE__->refers_to( artist => 'DBICTest::Schema::Artist', undef, {
is_deferrable => 1,
proxy => { artist_name => 'name' },
});
-__PACKAGE__->belongs_to( very_long_artist_relationship => 'DBICTest::Schema::Artist', 'artist', {
+__PACKAGE__->refers_to( very_long_artist_relationship => 'DBICTest::Schema::Artist', 'artist', {
is_deferrable => 1,
});
# in case this is a single-cd it promotes a track from another cd
-__PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track', 'single_track',
+__PACKAGE__->refers_to( single_track => 'DBICTest::Schema::Track', 'single_track',
{ join_type => 'left'}
);
{ order_by => 'producer.name' },
);
-__PACKAGE__->belongs_to('genre', 'DBICTest::Schema::Genre',
+__PACKAGE__->refers_to('genre', 'DBICTest::Schema::Genre',
{ 'foreign.genreid' => 'self.genreid' },
{
join_type => 'left',
#This second relationship was added to test the short-circuiting of pointless
#queries provided by undef_on_null_fk. the relevant test in 66relationship.t
-__PACKAGE__->belongs_to('genre_inefficient', 'DBICTest::Schema::Genre',
+__PACKAGE__->refers_to('genre_inefficient', 'DBICTest::Schema::Genre',
{ 'foreign.genreid' => 'self.genreid' },
{
join_type => 'left',
);
__PACKAGE__->set_primary_key(qw/cd producer/);
-__PACKAGE__->belongs_to(
+__PACKAGE__->refers_to(
'cd', 'DBICTest::Schema::CD',
{ 'foreign.cdid' => 'self.cd' }
);
-__PACKAGE__->belongs_to(
+__PACKAGE__->refers_to(
'producer', 'DBICTest::Schema::Producer',
{ 'foreign.producerid' => 'self.producer' },
{ on_delete => undef, on_update => undef },
);
__PACKAGE__->set_primary_key(qw/collection object/);
-__PACKAGE__->belongs_to( collection => "DBICTest::Schema::Collection",
+__PACKAGE__->refers_to( collection => "DBICTest::Schema::Collection",
{ "foreign.collectionid" => "self.collection" }
);
-__PACKAGE__->belongs_to( object => "DBICTest::Schema::TypedObject",
+__PACKAGE__->refers_to( object => "DBICTest::Schema::TypedObject",
{ "foreign.objectid" => "self.object" }
);
# Do not add unique constraints here - different groups are used throughout
# the ordered tests
-__PACKAGE__->belongs_to (secretkey => 'DBICTest::Schema::Encoded', 'encoded', {
+__PACKAGE__->refers_to (secretkey => 'DBICTest::Schema::Encoded', 'encoded', {
join_type => 'left'
});
);
# Normally this would appear as a FK constraint
-__PACKAGE__->belongs_to('cd_3', 'DBICTest::Schema::CD',
+__PACKAGE__->refers_to('cd_3', 'DBICTest::Schema::CD',
{ 'foreign.cdid' => 'self.cd' },
{ is_foreign_key_constraint => 0 },
);
qw/f_foo f_bar f_hello f_goodbye t_artist t_cd/
);
-__PACKAGE__->belongs_to('fourkeys', 'DBICTest::Schema::FourKeys', {
+__PACKAGE__->refers_to('fourkeys', 'DBICTest::Schema::FourKeys', {
'foreign.foo' => 'self.f_foo',
'foreign.bar' => 'self.f_bar',
'foreign.hello' => 'self.f_hello',
'foreign.goodbye' => 'self.f_goodbye',
});
-__PACKAGE__->belongs_to('twokeys', 'DBICTest::Schema::TwoKeys', {
+__PACKAGE__->refers_to('twokeys', 'DBICTest::Schema::TwoKeys', {
'foreign.artist' => 'self.t_artist',
'foreign.cd' => 'self.t_cd',
});
},
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to('artwork', 'DBICTest::Schema::Artwork', 'artwork_id');
+__PACKAGE__->refers_to('artwork', 'DBICTest::Schema::Artwork', 'artwork_id');
1;
},
);
__PACKAGE__->set_primary_key('liner_id');
-__PACKAGE__->belongs_to(
+__PACKAGE__->refers_to(
'cd', 'DBICTest::Schema::CD', 'liner_id'
);
},
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to('lyric', 'DBICTest::Schema::Lyrics', 'lyric_id');
+__PACKAGE__->refers_to('lyric', 'DBICTest::Schema::Lyrics', 'lyric_id');
1;
},
);
__PACKAGE__->set_primary_key('lyric_id');
-__PACKAGE__->belongs_to('track', 'DBICTest::Schema::Track', 'track_id');
+__PACKAGE__->refers_to('track', 'DBICTest::Schema::Track', 'track_id');
__PACKAGE__->has_many('lyric_versions', 'DBICTest::Schema::LyricVersion', 'lyric_id');
1;
);
__PACKAGE__->set_primary_key(qw/self_ref alias/);
-__PACKAGE__->belongs_to( self_ref => 'DBICTest::Schema::SelfRef' );
-__PACKAGE__->belongs_to( alias => 'DBICTest::Schema::SelfRef' );
+__PACKAGE__->refers_to( self_ref => 'DBICTest::Schema::SelfRef' );
+__PACKAGE__->refers_to( alias => 'DBICTest::Schema::SelfRef' );
1;
[qw/ tagid tag cd /],
);
-__PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', 'cd', {
+__PACKAGE__->refers_to( cd => 'DBICTest::Schema::CD', 'cd', {
proxy => [ 'year', { cd_title => 'title' } ],
});
__PACKAGE__->grouping_column ('cd');
-__PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, {
+__PACKAGE__->refers_to( cd => 'DBICTest::Schema::CD', undef, {
proxy => { cd_title => 'title' },
});
-__PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd', {
+__PACKAGE__->refers_to( disc => 'DBICTest::Schema::CD' => 'cd', {
proxy => 'year'
});
__PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' );
__PACKAGE__->might_have( lyrics => 'DBICTest::Schema::Lyrics', 'track_id' );
-__PACKAGE__->belongs_to(
+__PACKAGE__->refers_to(
"year1999cd",
"DBICTest::Schema::Year1999CDs",
{ "foreign.cdid" => "self.cd" },
{ join_type => 'left' }, # the relationship is of course optional
);
-__PACKAGE__->belongs_to(
+__PACKAGE__->refers_to(
"year2000cd",
"DBICTest::Schema::Year2000CDs",
{ "foreign.cdid" => "self.cd" },
},
);
__PACKAGE__->set_primary_key(qw/id/);
-__PACKAGE__->belongs_to('parent', 'TreeLike',
+__PACKAGE__->refers_to('parent', 'TreeLike',
{ 'foreign.id' => 'self.parent' });
__PACKAGE__->has_many('children', 'TreeLike', { 'foreign.parent' => 'self.id' });
);
__PACKAGE__->set_primary_key(qw/id1 id2/);
__PACKAGE__->add_unique_constraint('tktlnameunique' => ['name']);
-__PACKAGE__->belongs_to('parent', 'DBICTest::Schema::TwoKeyTreeLike',
+__PACKAGE__->refers_to('parent', 'DBICTest::Schema::TwoKeyTreeLike',
{ 'foreign.id1' => 'self.parent1', 'foreign.id2' => 'self.parent2'});
1;
);
__PACKAGE__->set_primary_key(qw/artist cd/);
-__PACKAGE__->belongs_to(
+__PACKAGE__->refers_to(
artist => 'DBICTest::Schema::Artist',
{'foreign.artistid'=>'self.artist'},
);
-__PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, { is_deferrable => 0, add_fk_index => 0 } );
+__PACKAGE__->refers_to( cd => 'DBICTest::Schema::CD', undef, { is_deferrable => 0, add_fk_index => 0 } );
__PACKAGE__->has_many(
'fourkeys_to_twokeys', 'DBICTest::Schema::FourKeys_to_TwoKeys', {
__PACKAGE__->set_primary_key('cdid');
__PACKAGE__->add_unique_constraint([ qw/artist title/ ]);
-__PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist' );
+__PACKAGE__->refers_to( artist => 'DBICTest::Schema::Artist' );
__PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track',
{ "foreign.cd" => "self.cdid" });
join (', ', __PACKAGE__->columns),
));
-__PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist' );
+__PACKAGE__->refers_to( artist => 'DBICTest::Schema::Artist' );
__PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track',
{ "foreign.cd" => "self.cdid" });
value => {});
__PACKAGE__->set_primary_key('left_id', 'right_id');
-__PACKAGE__->belongs_to(left => 'PrefetchBug::Left', 'left_id');
-__PACKAGE__->belongs_to(
+__PACKAGE__->refers_to(left => 'PrefetchBug::Left', 'left_id');
+__PACKAGE__->refers_to(
right => 'PrefetchBug::Right',
'right_id',
# {join_type => 'left'}
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'cd', 'ViewDeps::Result::CD',
+__PACKAGE__->refers_to( 'cd', 'ViewDeps::Result::CD',
{ "foreign.id" => "self.cd" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'artist', 'ViewDeps::Result::Artist',
+__PACKAGE__->refers_to( 'artist', 'ViewDeps::Result::Artist',
{ "foreign.id" => "self.artist" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'cd', 'ViewDeps::Result::CD',
+__PACKAGE__->refers_to( 'cd', 'ViewDeps::Result::CD',
{ "foreign.id" => "self.cd" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'cd', 'ViewDeps::Result::CD',
+__PACKAGE__->refers_to( 'cd', 'ViewDeps::Result::CD',
{ "foreign.id" => "self.cd" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'artist', 'ViewDeps::Result::Artist',
+__PACKAGE__->refers_to( 'artist', 'ViewDeps::Result::Artist',
{ "foreign.id" => "self.artist" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'artist', 'ViewDeps::Result::Artist',
+__PACKAGE__->refers_to( 'artist', 'ViewDeps::Result::Artist',
{ "foreign.id" => "self.artist" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'cd', 'ViewDepsBad::Result::CD',
+__PACKAGE__->refers_to( 'cd', 'ViewDepsBad::Result::CD',
{ "foreign.id" => "self.cd" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'artist', 'ViewDepsBad::Result::Artist',
+__PACKAGE__->refers_to( 'artist', 'ViewDepsBad::Result::Artist',
{ "foreign.id" => "self.artist" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'cd', 'ViewDepsBad::Result::CD',
+__PACKAGE__->refers_to( 'cd', 'ViewDepsBad::Result::CD',
{ "foreign.id" => "self.cd" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'cd', 'ViewDepsBad::Result::CD',
+__PACKAGE__->refers_to( 'cd', 'ViewDepsBad::Result::CD',
{ "foreign.id" => "self.cd" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'artist', 'ViewDepsBad::Result::Artist',
+__PACKAGE__->refers_to( 'artist', 'ViewDepsBad::Result::Artist',
{ "foreign.id" => "self.artist" },
);
__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( 'artist', 'ViewDepsBad::Result::Artist',
+__PACKAGE__->refers_to( 'artist', 'ViewDepsBad::Result::Artist',
{ "foreign.id" => "self.artist" },
);
mc_diag (<<'DG');
* Try a diamond multicreate
-Artist -> has_many -> Artwork_to_Artist -> belongs_to
+Artist -> has_many -> Artwork_to_Artist -> refers_to
/
- belongs_to <- CD <- belongs_to <- Artwork <-/
+ refers_to <- CD <- refers_to <- Artwork <-/
\
\-> Artist2
# test both sides of a 1:(1|0)
{
- for my $reldir ('might_have', 'belongs_to') {
+ for my $reldir ('might_have', 'refers_to') {
my $artist = $schema->resultset('Artist')->next;
my $new_track = $schema->resultset('Track')->new ({
isa_ok($cd, 'DBICTest::CD', 'Created CD object');
isa_ok($cd->artist, 'DBICTest::Artist', 'Created related Artist');
is($cd->artist->name, 'Fred Bloggs', 'Artist created correctly');
-}, 'simple create + parent (the stuff $rs belongs_to) ok');
+}, 'simple create + parent (the stuff $rs refers_to) ok');
lives_ok ( sub {
my $bm_rs = $schema->resultset('Bookmark');
# V V
# cd ------> artist
#
-# The current artwork belongs to a cd by artist1
+# The current artwork refers to a cd by artist1
# but the artwork itself is painted by artist2
#
# What we try is all possible permutations of join/prefetch
is ($_->tracks->count, 3, '3 tracks for CD' . $_->id );
}
-# Test a belongs_to prefetch of a has_many
+# Test a refers_to prefetch of a has_many
{
my $track_rs = $schema->resultset ('Track')->search (
{ 'me.cd' => { -in => [ $cd_rs->get_column ('cdid')->all ] } },
my $schema = DBICTest->init_schema();
-# a regular belongs_to prefetch
+# a regular refers_to prefetch
my $cds = $schema->resultset('CD')->search ({}, { prefetch => 'artist' } );
my $nulls = {
# note: we only requested "get all cds of all artists with rank 13 then order
# by the artist name and give me the fourth, fifth and sixth", consequently the
-# cds that belong to the same artist are unordered; fortunately we know that
+# cds that refer to the same artist are unordered; fortunately we know that
# the first artist have 3 cds and the second and third artist both have only
-# one, so the first 3 cds belong to the first artist and the fourth and fifth
-# cds belong to the second and third artist, respectively, and there's no sixth
+# one, so the first 3 cds refer to the first artist and the fourth and fifth
+# cds refer to the second and third artist, respectively, and there's no sixth
# row
is_deeply (
$filtered_cd_rs->all_hri,
is($tag->search_related('cd')->search_related('artist')->first->name,
'Caterwauler McCrae',
- 'chained belongs_to->belongs_to search_related ok');
+ 'chained refers_to->refers_to search_related ok');
-is($queries, 0, 'chained search_related after belontgs_to->belongs_to prefetch ran no queries');
+is($queries, 0, 'chained search_related after refers_to->refers_to prefetch ran no queries');
$queries = 0;
$schema->storage->debugcb(sub { $queries++; });
$schema->storage->debug(1);
$big_flop_cd->genre; #should not trigger a select query
- is($queries, 0, 'No SELECT made for belongs_to if key IS NULL');
+ is($queries, 0, 'No SELECT made for refers_to if key IS NULL');
$big_flop_cd->genre_inefficient; #should trigger a select query
- is($queries, 1, 'SELECT made for belongs_to if key IS NULL when undef_on_null_fk disabled');
+ is($queries, 1, 'SELECT made for refers_to if key IS NULL when undef_on_null_fk disabled');
$schema->storage->debug($sdebug);
$schema->storage->debugcb(undef);
}
is($trackset->count, 10, "Correct number of tracks for artist");
is($trackset->all, 10, "Correct number of track objects for artist");
-# now see about updating eveything that belongs to artist 2 to artist 3
+# now see about updating eveything that refers to artist 2 to artist 3
$artist = $schema->resultset("Artist")->find(2);
my $nartist = $schema->resultset("Artist")->find(3);
cmp_ok($artist->cds->count, '==', 1, "Correct orig #cds for artist");
# check if is_foreign_key_constraint attr is set
my $rs_normal = $schema->source('Track');
my $relinfo = $rs_normal->relationship_info ('cd');
-cmp_ok($relinfo->{attrs}{is_foreign_key_constraint}, '==', 1, "is_foreign_key_constraint defined for belongs_to relationships.");
+cmp_ok($relinfo->{attrs}{is_foreign_key_constraint}, '==', 1, "is_foreign_key_constraint defined for refers_to relationships.");
my $rs_overridden = $schema->source('ForceForeign');
my $relinfo_with_attr = $rs_overridden->relationship_info ('cd_3');
-cmp_ok($relinfo_with_attr->{attrs}{is_foreign_key_constraint}, '==', 0, "is_foreign_key_constraint defined for belongs_to relationships with attr.");
+cmp_ok($relinfo_with_attr->{attrs}{is_foreign_key_constraint}, '==', 0, "is_foreign_key_constraint defined for refers_to relationships with attr.");
# check that relationships below left join relationships are forced to left joins
-# when traversing multiple belongs_to
+# when traversing multiple refers_to
my $cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => 'cd' } });
is($cds->count, 1, "subjoins under left joins force_left (string)");
lives_ok {
my $artista = $_->artist;
my $artistb = $_->artist_test_m2m;
- ok($artista->rank < 10 ? $artistb : 1, 'belongs_to with custom rel works.');
+ ok($artista->rank < 10 ? $artistb : 1, 'refers_to with custom rel works.');
my $artistc = $_->artist_test_m2m_noopt;
- ok($artista->rank < 10 ? $artistc : 1, 'belongs_to with custom rel works even in non-simplified.');
- } 'belongs_to works with custom rels';
+ ok($artista->rank < 10 ? $artistc : 1, 'refers_to with custom rel works even in non-simplified.');
+ } 'refers_to works with custom rels';
}
@artists = ();
__PACKAGE__->add_columns(qw/id ancestor_id/);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many(children => __PACKAGE__, 'id');
- __PACKAGE__->belongs_to(parent => __PACKAGE__, 'id', { join_type => 'left' } );
+ __PACKAGE__->refers_to(parent => __PACKAGE__, 'id', { join_type => 'left' } );
__PACKAGE__->has_many(subthings => 'DBICTest::SubThing', 'thing_id');
}
use base qw/DBIx::Class::Core/;
__PACKAGE__->table('subthing');
__PACKAGE__->add_columns(qw/thing_id/);
- __PACKAGE__->belongs_to(thing => 'DBICTest::Thing', 'thing_id');
- __PACKAGE__->belongs_to(thing2 => 'DBICTest::Thing', 'thing_id', { join_type => 'left' } );
+ __PACKAGE__->refers_to(thing => 'DBICTest::Thing', 'thing_id');
+ __PACKAGE__->refers_to(thing2 => 'DBICTest::Thing', 'thing_id', { join_type => 'left' } );
}
my $schema = DBICTest->init_schema;
is_deeply(
_instance($s)->reverse_relationship_info('thing'),
{ subthings => $t->relationship_info('subthings') },
- 'reverse_rel_info works cross-class belongs_to direction',
+ 'reverse_rel_info works cross-class refers_to direction',
);
is_deeply(
_instance($s)->reverse_relationship_info('thing2'),
{ subthings => $t->relationship_info('subthings') },
- 'reverse_rel_info works cross-class belongs_to direction 2',
+ 'reverse_rel_info works cross-class refers_to direction 2',
);
is_deeply(
is_deeply(
_instance($t)->reverse_relationship_info('parent'),
{ children => $t->relationship_info('children') },
- 'reverse_rel_info works in-class belongs_to direction',
+ 'reverse_rel_info works in-class refers_to direction',
);
is_deeply(
_instance($t)->reverse_relationship_info('children'),
is( $bookmark->link->id, 1, 'Initial relation id' );
$bookmark->set_column( 'link', 9 );
-is( $bookmark->link->id, 9, 'Correct object re-selected after belongs_to set' );
+is( $bookmark->link->id, 9, 'Correct object re-selected after refers_to set' );
$bookmark->discard_changes;
-is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
+is( $bookmark->link->id, 1, 'Pulled the correct old object after refers_to reset' );
$bookmark->link($new_link);
is( $bookmark->get_column('link'), 9, 'Correct column set from related' );
$bookmark->discard_changes;
-is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
+is( $bookmark->link->id, 1, 'Pulled the correct old object after refers_to reset' );
$bookmark->link(9);
is( $bookmark->link->id, 9, 'Correct object selected on deflated accessor set');
$bookmark->discard_changes;
-is( $bookmark->link->id, 1, 'Pulled the correct old object after belongs_to reset' );
+is( $bookmark->link->id, 1, 'Pulled the correct old object after refers_to reset' );
$bookmark->update({ link => 9 });
$lyric->track_id(6);
my $track6 = $lyric->track;
-is( $track6->trackid, 6, 'Correct object re-selected after belongs_to set');
+is( $track6->trackid, 6, 'Correct object re-selected after refers_to set');
$lyric->discard_changes;
-is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset');
+is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after refers_to reset');
$lyric->track($track6);
is( $lyric->track_id, 6, 'Correct column set from related');
$lyric->discard_changes;
-is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after belongs_to reset');
+is( $lyric->track->trackid, 5, 'Pulled the correct old rel object after refers_to reset');
$lyric->update({ track => $track6 });
is( $lyric->track->trackid, 6, 'Correct relationship obj after update' );