--- /dev/null
+use Test::More;\r
+\r
+# this test will check to see if you can have 2 columns\r
+# in the same class pointing at the same other class\r
+#\r
+# example:\r
+#\r
+# +---------+ +--------------+\r
+# | SelfRef | | SelfRefAlias |\r
+# +---------+ 1-M +--------------+\r
+# | id |-------| self_ref | --+\r
+# | name | | alias | --+\r
+# +---------+ +--------------+ |\r
+# /|\ |\r
+# | |\r
+# +--------------------------------+\r
+#\r
+# see http://use.perl.org/~LTjake/journal/24876 for the\r
+# issue with CDBI\r
+\r
+plan tests => 5;\r
+\r
+use lib qw( t/lib );\r
+\r
+use_ok( 'DBICTest' );\r
+\r
+my $item = DBICTest::SelfRef->find( 1 );\r
+is( $item->name, 'First', 'proper start item' );\r
+\r
+my @aliases = $item->aliases;\r
+\r
+is( scalar @aliases, 1, 'proper number of aliases' );\r
+\r
+my $orig = $aliases[ 0 ]->self_ref;\r
+my $alias = $aliases[ 0 ]->alias;\r
+\r
+is( $orig->name, 'First', 'proper original' );\r
+is( $alias->name, 'Second', 'proper alias' );
\ No newline at end of file
CREATE TABLE onekey (id INTEGER NOT NULL PRIMARY KEY,
artist INTEGER NOT NULL, cd INTEGER NOT NULL );
+CREATE TABLE self_ref (id INTEGER NOT NULL PRIMARY KEY,
+ name VARCHAR );
+
+CREATE TABLE self_ref_alias (self_ref INTEGER NOT NULL, alias INTEGER NOT NULL,
+ PRIMARY KEY( self_ref, alias ) );
+
INSERT INTO artist (artistid, name) VALUES (1, 'Caterwauler McCrae');
INSERT INTO artist (artistid, name) VALUES (2, 'Random Boy Band');
INSERT INTO onekey (id, artist, cd) VALUES (2, 1, 2);
INSERT INTO onekey (id, artist, cd) VALUES (3, 2, 2);
+
+INSERT INTO self_ref(id, name) VALUES (1, 'First');
+
+INSERT INTO self_ref(id, name) VALUES (2, 'Second');
+
+INSERT INTO self_ref_alias(self_ref, alias) VALUES (1, 2);
EOSQL
$dbh->do($_) for split(/\n\n/, $sql);
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_classes(qw/
- Artist CD Track Tag LinerNotes OneKey TwoKeys FourKeys/);
+ Artist CD Track Tag LinerNotes OneKey TwoKeys FourKeys SelfRef SelfRefAlias /);
1;
--- /dev/null
+package DBICTest::Schema::SelfRef;\r
+\r
+use base 'DBIx::Class::Core';\r
+\r
+__PACKAGE__->table('self_ref');\r
+__PACKAGE__->add_columns(qw/id name/);\r
+__PACKAGE__->set_primary_key('id');\r
+__PACKAGE__->add_relationship(\r
+ aliases => 'DBICTest::Schema::SelfRefAlias',\r
+ { 'foreign.self_ref' => 'self.id' },\r
+ { accessor => 'multi' }\r
+);\r
+\r
+1;\r
--- /dev/null
+package DBICTest::Schema::SelfRefAlias;\r
+\r
+use base 'DBIx::Class::Core';\r
+\r
+__PACKAGE__->table('self_ref_alias');\r
+__PACKAGE__->add_columns(qw/self_ref alias/);\r
+__PACKAGE__->set_primary_key('self_ref alias');\r
+__PACKAGE__->add_relationship(\r
+ self_ref => 'DBICTest::Schema::SelfRef',\r
+ { 'foreign.id' => 'self.self_ref' },\r
+ { accessor => 'single' }\r
+\r
+);\r
+__PACKAGE__->add_relationship(\r
+ alias => 'DBICTest::Schema::SelfRef',\r
+ { 'foreign.id' => 'self.alias' },\r
+ { accessor => 'single' }\r
+);\r
+\r
+1;\r