# Force the order of the referenced fields to be the same as
# ->add_columns method.
my $idx;
- my %other_columns_idx = map {$_ => $idx++} $othertable->columns;
+ my %other_columns_idx = map {$_ => ++$idx } $othertable->columns;
@refkeys = sort { $other_columns_idx{$a} cmp $other_columns_idx{$b} } @refkeys;
my @keys = map {$rel_info->{cond}->{$_} =~ /^\w+\.(\w+)$/} @cond;
$schema->storage->debug(1);
my $tree_like =
- $schema->resultset('TreeLike')->find(4,
+ $schema->resultset('TreeLike')->find(5,
{ join => { parent => { parent => 'parent' } },
prefetch => { parent => { parent => 'parent' } } });
cmp_ok($queries, '==', 1, 'Only one query run');
-$tree_like = $schema->resultset('TreeLike')->search({'me.id' => 1});
+$tree_like = $schema->resultset('TreeLike')->search({'me.id' => 2});
$tree_like = $tree_like->search_related('children')->search_related('children')->search_related('children')->first;
is($tree_like->name, 'quux', 'Tree search_related ok');
$tree_like = $schema->resultset('TreeLike')->search_related('children',
- { 'children.id' => 2, 'children_2.id' => 3 },
+ { 'children.id' => 3, 'children_2.id' => 4 },
{ prefetch => { children => 'children' } }
)->first;
is(eval { $tree_like->children->first->children->first->name }, 'quux',
'Tree search_related with prefetch ok');
$tree_like = eval { $schema->resultset('TreeLike')->search(
- { 'children.id' => 2, 'children_2.id' => 5 },
+ { 'children.id' => 3, 'children_2.id' => 6 },
{ join => [qw/children children/] }
- )->search_related('children', { 'children_4.id' => 6 }, { prefetch => 'children' }
+ )->search_related('children', { 'children_4.id' => 7 }, { prefetch => 'children' }
)->first->children->first; };
is(eval { $tree_like->name }, 'fong', 'Tree with multiple has_many joins ok');
treelike => [
{
'display' => 'treelike->treelike for parent',
- 'name' => 'treelike_fk_parent', 'index_name' => 'parent',
+ 'name' => 'treelike_fk_parent_fk', 'index_name' => 'parent_fk',
'selftable' => 'treelike', 'foreigntable' => 'treelike',
- 'selfcols' => ['parent'], 'foreigncols' => ['id'],
+ 'selfcols' => ['parent_fk'], 'foreigncols' => ['id'],
on_delete => 'CASCADE', on_update => 'CASCADE', deferrable => 1,
},
],
'display' => 'forceforeign->artist',
'name' => 'forceforeign_fk_artist', 'index_name' => 'artist',
'selftable' => 'forceforeign', 'foreigntable' => 'artist',
- 'selfcols' => ['artist'], 'foreigncols' => ['artist_id'],
+ 'selfcols' => ['artist'], 'foreigncols' => ['artistid'],
on_delete => '', on_update => '', deferrable => 1,
},
],
my $args = shift || {};
if ($ENV{"DBICTEST_SQLT_DEPLOY"}) {
-
-#$schema->create_ddl_dir([qw/MySQL/], $schema->VERSION, '.', undef, $args);
-$schema->deploy($args);
-
+ $schema->deploy($args);
} else {
open IN, "t/lib/sqlite.sql";
my $sql;
[ 1, 2 ],
[ 1, 3 ],
]);
-
- # $schema->populate('TreeLike', [
- # [ qw/id parent name/ ],
- # [ 0, 0, 'root' ],
- # [ 1, 0, 'foo' ],
- # [ 2, 1, 'bar' ],
- # [ 5, 1, 'blop' ],
- # [ 3, 2, 'baz' ],
- # [ 4, 3, 'quux' ],
- # [ 6, 2, 'fong' ],
- # ]);
+
+ $schema->populate('TreeLike', [
+ [ qw/id parent_fk name/ ],
+ [ 1, undef, 'root' ],
+ [ 2, 1, 'foo' ],
+ [ 3, 2, 'bar' ],
+ [ 6, 2, 'blop' ],
+ [ 4, 3, 'baz' ],
+ [ 5, 4, 'quux' ],
+ [ 7, 3, 'fong' ],
+ ]);
$schema->populate('Track', [
[ qw/trackid cd position title/ ],
__PACKAGE__->table('treelike');
__PACKAGE__->add_columns(
'id' => { data_type => 'integer', is_auto_increment => 1 },
- 'parent' => { data_type => 'integer' },
+ 'parent_fk' => { data_type => 'integer' , is_nullable=>1},
'name' => { data_type => 'varchar',
size => 100,
},
);
__PACKAGE__->set_primary_key(qw/id/);
__PACKAGE__->belongs_to('parent', 'TreeLike',
- { 'foreign.id' => 'self.parent' });
-__PACKAGE__->has_many('children', 'TreeLike', { 'foreign.parent' => 'self.id' });
+ { 'foreign.id' => 'self.parent_fk' });
+__PACKAGE__->has_many('children', 'TreeLike', { 'foreign.parent_fk' => 'self.id' });
## since this is a self referential table we need to do a post deploy hook and get
## some data in while constraints are off
--
CREATE TABLE treelike (
id INTEGER PRIMARY KEY NOT NULL,
- parent integer NOT NULL,
+ parent_fk integer NULL,
name varchar(100) NOT NULL
);