GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
DBIx::Lite::Schema(3) User Contributed Perl Documentation DBIx::Lite::Schema(3)

DBIx::Lite::Schema

version 0.33

This class holds the very loose schema 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.

An empty DBIx::Lite::Schema is created every time you create a DBIx::Lite object. Then you can access it to customize it. Otherwise, you can prepare a Schema object and reutilize it across multiple connections:

    my $schema = DBIx::Lite::Schema->new;
    my $conn1 = DBIx::Lite->new(schema => $schema)->connect(...);
    my $conn2 = DBIx::Lite->new(schema => $schema)->connect(...);

The constructor takes no arguments.

This method accepts a table name and returs the DBIx::Lite::Schema::Table object corresponding to the requested table. You can then call methods on it.

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

This methods sets up a 1-to-N relationship between two tables. Just pass two table names to it, appending the relation key column name:

    $schema->one_to_many('authors.id' => 'books.author_id');

This will have the following effects:

provide a "books" accessor method in the authors Result objects
provide a "books" accessor method in the authors ResultSet objects
allow to call "<$author-"insert_related('books', {...})>>

If you supply a third argument, it will be used to set up the reverse accessor method. For example this will install a "author" accessor method in the books Result objects:

    $schema->one_to_many('authors.id' => 'books.author_id', 'author');

If you also want to customize the accessor for the first table, you can supply an arrayref with both accessor names. This can be needed when the second table has two fields referencing the same table:

    $schema->one_to_many('authors.id' => 'books.author_id', [ 'books_as_author', 'author' ]);
    $schema->one_to_many('authors.id' => 'books.curator_id', [ 'books_as_curator', 'curator' ]);

Note that relationships can be chained:

    $dbix->schema->one_to_many('authors.id' => 'books.author_id');
    $dbix->schema->one_to_many('books.id' => 'chapters.books_id');
    my @chapters = $dbix
        ->table('authors')
        ->search({ country => 'IT' })
        ->books
        ->chapters
        ->search({ page_count => { '>' => 20 } })
        ->all;

You can use the same approach to traverse many-to-many relationships.

Alessandro Ranellucci <aar@cpan.org>

This 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.

2021-09-07 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.