package Person;
use base 'MyCDBI';
__PACKAGE__->table('people');
__PACKAGE__->columns(All => qw(id name));
# CREATE TABLE people (
# id INT NOT NULL auto_increment,
# name VARCHAR(255) NOT NULL,
# PRIMARY KEY (id),
# UNIQUE (name)
# );
####
package Person::Relationship;
use base 'MyCDBI';
__PACKAGE__->table('people_tree');
__PACKAGE__->columns(Primary => qw(parent child));
__PACKAGE__->has_a(parent => 'Person');
__PACKAGE__->has_a(child => 'Person');
# CREATE TABLE people_tree (
# parent int NOT NULL REFERENCES people,
# child int NOT NULL REFERENCES people,
# PRIMARY KEY (parent,child)
# );
####
Person->has_many(children => [ Person::Relationship => child ]);
Person->has_many(parents => [ Person::Relationship => parent ]);
####
Person->has_many({ self_id => parent }, children => [ Person::Relationship => child ]);
Person->has_many({ self_id => child }, parents => [ Person::Relationship => parent ]);