NAME

ObjectDB::Schema - Schema class

SYNOPSIS

package Article;

use strict;
use warnings;

use base 'ObjectDB';

__PACKAGE__->schema(
    table          => 'article',
    columns        => [qw/id category_id author_id title/],
    primary_keys   => ['id'],
    auto_increment => 'id',

    relationships => {
        author => {
            type  => 'many to one',
            class => 'Author',
            map   => {author_id => 'id'}
        },
        category => {
            type  => 'many to one',
            class => 'Category',
            map   => {category_id => 'id'}
        },
        tags => {
            type      => 'many to many',
            map_class => 'ArticleTagMap',
            map_from  => 'article',
            map_to    => 'tag'
        },
        comments => {
            type  => 'one to many',
            class => 'Comment',
            where => [type => 'article'],
            map   => {id => 'master_id'}
        }
    }
);

1;

DESCRIPTION

ATTRIBUTES

attr

METHODS

new

Not called externally, but sets the following attributes:

table

__PACKAGE__->schema(
    table => 'article
    ...

Table name.

columns

__PACKAGE__->schema(
    ...
    columns => [qw/id title/]
    ...

Sets columns.

primary_keys

__PACKAGE__->schema(
    ...
    primary_keys => [qw/id/]
    ...

Sets primary keys. Could be multiple of course.

unique_keys

__PACKAGE__->schema(
    ...
    unique_keys => [qw/title/]
    ...

Sets unique keys. Could be multiple of course.

auto_increment

__PACKAGE__->schema(
    ...
    auto_increment => 'id'
    ...

Sets auto increment key. Is altered on object database insertion.

relationships

__PACKAGE__->schema(
    ...
    relationships => {
        author => {
            type  => 'many to one',
            class => 'Author',
            map   => {author_id => 'id'}
        },
    ...

Sets relationships. For more information see ObjectDB::Relationship.

is_column

$article->schema->is_column('title'); # true

Returns true when argument is a column. False otherwise.

is_primary_key

$article->schema->is_primary_key('title'); # false

Returns true when argument is a primary key. False otherwise.

is_auto_increment

$article->schema->is_auto_increment('id'); # true

Returns true when argument is an auto increment column. False otherwise.

is_unique_key

$article->schema->is_unique_key('title'); # false

Returns true when argument is a unique key. False otherwise.

columns

my @columns = $article->schema->columns;

Returns schema columns.

primary_keys

my @primary_keys = $article->schema->primary_keys;

Returns primary keys.

unique_keys

my @unique_keys = $article->schema->unique_keys;

Returns unique keys.

add_column

__PACKAGE__->add_column(content => {default => 'foo'});

Adds column to the schema. Usually used when you extend existing class and want to add few new columns.

add_columns

__PACKAGE__->add_column(qw/content image/);

Adds columns to the schema. Uses add_column.

add_relationship

__PACKAGE__->add_relationship(
    comments => {
        type  => 'one to many',
        class => 'Comment',
        where => [type => 'article'],
        map   => {id => 'master_id'}
    }
);

Adds relationhips to the schema. Usually used when you extend existing class and want to add few new relationhips.

add_relationships

__PACKAGE__->add_relationships(
    comments => {
        type  => 'one to many',
        class => 'Comment',
        where => [type => 'article'],
        map   => {id => 'master_id'}
    },
    ...
);

Adds relationhips to the schema. Uses add_relationhip.

del_column

__PACKAGE__->del_column('content');

Deletes column from the schema. Usually used when you extend existing class and want to delete few old columns.

AUTHOR

Viacheslav Tykhanovskyi, vti@cpan.org.

COPYRIGHT

Copyright (C) 2009, Viacheslav Tykhanovskyi.

This program is free software, you can redistribute it and/or modify it under the same terms as Perl 5.10.