21b1ef35a7314bbba6bc559aaedf958f770d63ae
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / Schema / TreeLike.pm
1 package # hide from PAUSE
2     DBICTest::Schema::TreeLike;
3
4 use base qw/DBICTest::BaseResult/;
5
6 __PACKAGE__->table('treelike');
7 __PACKAGE__->add_columns(
8   'id' => { data_type => 'integer', is_auto_increment => 1 },
9   'parent' => { data_type => 'integer' , is_nullable=>1},
10   'name' => { data_type => 'varchar',
11     size      => 100,
12  },
13 );
14 __PACKAGE__->set_primary_key(qw/id/);
15 __PACKAGE__->belongs_to('parent', 'TreeLike',
16                           { 'foreign.id' => 'self.parent' });
17 __PACKAGE__->has_many('children', 'TreeLike', { 'foreign.parent' => 'self.id' });
18
19 ## since this is a self referential table we need to do a post deploy hook and get
20 ## some data in while constraints are off
21
22  sub sqlt_deploy_hook {
23    my ($self, $sqlt_table) = @_;
24
25    ## We don't seem to need this anymore, but keeping it for the moment
26    ## $sqlt_table->add_index(name => 'idx_name', fields => ['name']);
27  }
28 1;