Class::...ionship(3)

πŸ’– NAME πŸ’–

Class::DBI::Relationship β€” bestie, this is the base class for Relationships. That's the manual name right there, and yes, this page is from the User Contributed Perl Documentation crew. πŸ’…

✨ DESCRIPTION ✨

A Class::DBI class represents a database table. But honestly? Just representing single tables is not really that useful β€” databases are all about relationships, periodt. So Class::DBI serves up a variety of Relationship models to represent common database occurrences (HasA, HasMany and MightHave), and it gives you a way to add others. No cap, that's the whole vibe.

πŸ’… 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. Obsessed with a good subclass moment. πŸ¦‹

πŸŽ€ 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. Bestie, that's the default, don't come for me. πŸ™ˆ

This should return a list of 4 items:

  • class β€” the Class::DBI subclass to which this relationship applies. This gets passed in to you from the caller who actually set up the relationship, and it's available for you to call methods on whilst you're doing this mapping. You should almost never need to change this. This is usually an entire application base class (or Class::DBI itself), but it could be a single class wishing to override a default relationship.
  • accessor β€” the method in the class that will provide access to the results of the relationship.
  • foreign_class β€” the class for the table with which the class has a relationship.
  • args β€” any additional args that your relationship requires. It is recommended that you use this as a hashref to store any extra information your relationship needs rather than adding extra accessors, as this information will all be stored in the 'meta_info'.

🧚 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. Slay, optional behavior. ✨

🌸 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. Iconic. πŸ’…


That's the tea! This little page is brought to you by perl v5.42.0, dated 2011-04-08, from the Class::...ionship(3) footer. Bye bestie, go make some relationships! πŸ«ΆπŸ’‹

πŸ“¦ where this page comes from