NAME
Class::DBI::Relationship::IsA - A Class::DBI module for 'Is A' relationships
DESCRIPTION
Class::DBI::Relationship::IsA Provides an Is A relationship between Class::DBI classes/tables.
By using this module you can emulate some features of inheritance both within your database and classes through the Class::DBI API.
NOTE: This module is still experimental, several very nasty bugs have been found (and fixed) others may still be lurking - see CAVEATS AND BUGS below.
Warning Will Robinson!
SYNOPSIS
In your database (assuming mysql):
create table person (
personid int primary key auto_increment,
firstname varchar(32),
initials varchar(16),
surname varchar(64),
date_of_birth datetime
);
create table artist (
artistid int primary key auto_increment,
alias varchar(128),
person int
);
In your classes:
package Music::DBI;
use base 'Class::DBI';
Music::DBI->connection('dbi:mysql:dbname', 'username', 'password');
__PACKAGE__->add_relationship_type(is_a => 'Class::DBI::Relationship::IsA');
Superclass:
package Music::Person;
use base 'Music::DBI';
Music::Person->table('person');
Music::Person->columns(All => qw/personid firstname initials surname date_of_birth/);
Music::Person->columns(Primary => qw/personid/); # Good practice, less likely to break IsA
Child class:
package Music::Artist;
use base 'Music::DBI';
use Music::Person; # required for access to Music::Person methods
Music::Artist->table('artist');
Music::Artist->columns(All => qw/artistid alias/);
Music::Person->columns(Primary => qw/personid/); # Good practice, less likely to break IsA
Music::Artist->has_many(cds => 'Music::CD');
Music::Artist->is_a(person => 'Person'); # Music::Artist inherits accessors from Music::Person
... elsewhere ...
use Music::Artist;
my $artist = Music::Artist->create( {firstname=>'Sarah', surname=>'Geller', alias=>'Buffy'});
$artist->initials('M');
$artist->update();
BUGS AND CAVEATS
* Multiple inheritance is not supported, this is unlikely to change for the forseable future
* is_a must be called after all other cdbi relationship methods otherwise inherited methods and accessors may be over-ridden or clash unexpectedly
* non Class::DBI attributes and methods are not inherited via this module
* The update method is called on the inherited object when the inhertiting object has update called
* Always specify the primary key using columns(Primary => qw/../) if you don't bad things could happen, think of the movies 'Tremors', 'Poltergeist' and 'Evil Dead' all rolled into one but without any heros.
* Very Bad Things can and may occur when using this module even if you use good practice and are cautious -- this includes but is not limited to infinite loops, memory leaks and data corruption.
DEPENDANCIES
SEE ALSO
AUTHOR
Richard Hundt, <richard@webtk.org.uk>
MAINTAINER
Aaron Trevena <aaron.trevena@droogs.org>
COPYRIGHT
Licensed for use, modification and distribution under the Artistic and GNU GPL licenses.
Copyright (C) 2004 by Richard Hundt and Aaron Trevena
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.