The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::Lite::Schema::Table

VERSION

version 0.11

OVERVIEW

This class holds the very loose table definitions that enable some advanced features of DBIx::Lite. Note that you can do all main operations, including searches and manipulations, with no need to define any schema.

This class is not supposed to be instantiated manually. You usually get your Table objects by calling the table() method on a DBIx::Lite::Schema object:

    my $table = $dbix->schema->table('books');

METHODS

pk

This method accepts a list of fields to be used as the table primary key. Setting a primary key enables update() and delete() methods on DBIx::Lite::Row objects.

    $dbix->schema->table('books')->pk('id');

autopk

This method works like pk but also marks the supplied column name as an autoincrementing key. This will trigger the retrieval of the autoincremented id upon creation of new records with the insert() method. autopk() only accepts a single column.

    $dbix->schema->table('books')->autopk('id');

You probably want to use autopk() for most tables, and only use pk for those many-to-many relationship tables not having an autoincrementing id:

    $dbix->schema->one_to_many('users.id' => 'users_tasks.user_id');
    $dbix->schema->one_to_many('tasks.id' => 'users_tasks.task_id');
    $dbix->schema->table('users')->autopk('id');
    $dbix->schema->table('tasks')->autopk('id');
    $dbix->schema->table('users_tasks')->pk('user_id', 'task_id');

class

This method accepts a package name that DBIx::Lite will use for this table's Result objects. You don't need to declare such package name anywhere else, as DBIx::Lite will create that class for you.

    $dbix->schema->table('books')->class('My::Book');
    my $book = $dbix->table('books')->find({ id => 2 });
    # $book is a My::Book

The class will subclass DBIx::Lite::Row. You can also supply an existing package name or declare your methods inline:

    $dbix->schema->table('books')->class('My::Book');
    
    sub My::Book::get_page_count {
        my $self = shift;
        return $self->page_count;
    }

resultset_class

This method accepts a package name that DBIx::Lite will use for this table's ResultSet objects. You don't need to declare such package name anywhere else, as DBIx::Lite will create that class for you.

    $dbix->schema->table('books')->resultset_class('My::Book::ResultSet');
    my $books_rs = $dbix->table('books')->search({ year => 2012 });
    # $books_rs is a My::Book::ResultSet

The class will subclass DBIx::Lite::ResultSet. You can also supply an existing package name or declare your methods inline:

    $dbix->schema->table('books')->resultset_class('My::Book::ResultSet');
    
    sub My::Book::ResultSet::get_multilanguage {
        my $self = shift;
        return $self->search({ multilanguage => 1 });
    }

AUTHOR

Alessandro Ranellucci <aar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Alessandro Ranellucci.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.