 こんなかんじのアイコンです
 こんなかんじのアイコンですPerl と ミルキィホームズが好きです
CREATE TABLE person ( /* 人間 */
  id   INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT    NOT NULL,
);
CREATE TABLE detective ( /* 探偵 */
  id        INTEGER PRIMARY KEY AUTOINCREMENT,
  person_id INTEGER NOT NULL,
  toys      TEXT  NOT NULL,
  FOREIGN KEY(person_id) REFERENCES person(id)
);
CREATE TABLE police ( /* 警察 */
  id        INTEGER PRIMARY KEY AUTOINCREMENT,
  person_id INTEGER NOT NULL,
  iq        INTEGER,
  FOREIGN KEY(person_id) REFERENCES person(id)
);
my $row = $db->single('detective', { person_id => 100 });
$row->name; #これは無理(name は親テーブル person にあるから)
my $row = $db->create({ id => 100 }); # id=100が探偵さんだとして
$row->toys; #これができない(あるいはちょっとめんどい)
package Detective;
use Mouse;
extends 'Person';
...
package Person
use Mouse;
...
sub create {
    my ($class, $id) = @_;
    # 区分を親側で持っておいて、親の$row を子に渡して、
    # 子側で自分のテーブルを引く方が使いやすくてオススメではあります。下記のは説明用
    my $person_row = db->single('person', { id => $id });
    my $detective_row = db->single('detective', { person_id => $id });
    if ( defined $detective_row ) { #探偵が返る。name も引ける
        return Detective->create($person_row->name, $detective_row);
    }
    my $police_row = db->single('police', { person_id => $id });
    if ( defined $police_row ) { #警察が返る
        return Police->create($person_row->name, $police_row);
    }
    die "探偵でも警察でもないのはダメダメですー"
}
Use a spacebar or arrow keys to navigate