info > Class::DBI::Relationship

Class::DBI::RelationshUserpContributed Perl DocumClass::DBI::Relationship(3pm)

📖 NAME

Class::DBI::Relationship - base class for Relationships

🚀 Quick Reference

Use Case Command Description
Remap relationship arguments remap_arguments() Transform arguments into the required structure for the relationship
Define triggers for relationship triggers() Return list of triggers (before_create, after_create)
Define methods for relationship methods() Return list of methods to facilitate the relationship

📘 DESCRIPTION

A Class::DBI class represents a database table. But merely being able to represent single tables isn't really that useful - databases are all about relationships.

So, Class::DBI provides a variety of Relationship models to represent common database occurences (HasA, HasMany and MightHave), and provides a way to add others.

🔧 SUBCLASSING

Relationships should inherit from Class::DBI::Relationship, and provide a variety of methods to represent the relationship. For examples of how these are used see Class::DBI::Relationship::HasA, Class::DBI::Relationship::HasMany and Class::DBI::Relationship::MightHave.

↪ remap_arguments

sub remap_arguments {
        my $self = shift;
        # process @_;
        return ($class, accessor, $foreign_class, $args)
}

Subclasses should define a remap_arguments method that takes the arguments with which your relationship method will be called, and transforms them into the structure that the Relationship modules requires. If this method is not provided, then it is assumed that your method will be called with these 3 arguments in this order.

This should return a list of 4 items:

⚡ triggers

sub triggers {
        return (
                before_create => sub { ... },
                after_create  => sub { ... },
        );
}

Subclasses may define a triggers method that returns a list of triggers that the relationship needs. This method can be omitted if there are no triggers to be set up.

🔧 methods

sub methods {
        return (
                method1 => sub { ... },
                method2 => sub { ... },
        );
}

Subclasses may define a methods method that returns a list of methods to facilitate the relationship that should be created in the calling Class::DBI class. This method can be omitted if there are no methods to be set up.

perl v5.32.0 2020-12-28 Class::DBI::Relationship(3pm)

Class::DBI::Relationship
📖 NAME 🚀 Quick Reference 📘 DESCRIPTION 🔧 SUBCLASSING
↪ remap_arguments ⚡ triggers 🔧 methods

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-14 21:48 @2600:1f28:365:80b0:4d23:66fa:c2bb:7bae
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!