|
NAMEDBIx::Lite::Schema::TableVERSIONversion 0.33OVERVIEWThis 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'); pkThis method accepts one or more 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'); $dbix->schema->table('books')->pk('foo', 'bar'); autopkThis method can be used as an alternative to pk but it will only accept a single column name, which will be marked as an autoincrementing key. This will trigger the retrieval of the autoincremented id upon creation of new records with the "insert()" method.$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'); classThis 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 declare your additional methods inline: $dbix->schema->table('books')->class('My::Book'); sub My::Book::get_page_count { my $self = shift; return $self->page_count; } If you want to use an existing class you might need to provide DBIx::Lite with some glue for correctly inflating objects without messing with your class storage. The "class()" method accepts three more optional arguments: $dbix->schema->table('books')->class('My::Book', $constructor, $storage, $inflator);
resultset_classThis 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 }); } AUTHORAlessandro Ranellucci <aar@cpan.org>COPYRIGHT AND LICENSEThis software is copyright (c) 2021 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.
Visit the GSP FreeBSD Man Page Interface. |