Relationship(3pm)

πŸ“¦
version 1.2 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Okay bestie, welcome to the Relationship(3pm) page β€” a User Contributed Perl Documentation moment. The module is Class::DBI::Loader::Relationship, and its whole vibe is: Easier relationship specification in CDBI::L ✨


✨ SYNOPSIS ✨

Start with the module and a loader, like this:

  use Class::DBI::Loader::Relationship;

  my $loader = Class::DBI::Loader->new( dsn => "mysql:beerdb",
                                        namespace => "BeerDB");

So instead of spelling out this whole stack of relationship declarations:

    BeerDB::Brewery->has_many(beers => "BeerDB::Beer");
    BeerDB::Beer->has_a(brewery => "BeerDB::Brewery");

    BeerDB::Handpump->has_a(beer => "BeerDB::Beer");
    BeerDB::Handpump->has_a(pub => "BeerDB::Pub");
    BeerDB::Pub->has_many(beers => [ BeerDB::Handpump => 'beer' ]);
    BeerDB::Beer->has_many(pubs => [ BeerDB::Handpump => 'pub' ]);

You can just say:

    $loader->relationship( "a brewery produces beers" );
    $loader->relationship( "a pub has beers on handpumps" );

Slay. That's the whole point. 🫢


🌸 DESCRIPTION 🌸

This module acts as a mix-in, adding the relationship method to Class::DBI::Loader. And because Class::DBI::Loader already knows how to map between table names and class names, there ought to be no need to replicate the names. Iconic behavior, honestly. πŸ‘‘

Also β€” and this is common but not universal β€” people often want reverse relationships defined for has-many relationships, and they want has-a relationships defined for the linkages surrounding a many-to-many table. So the aim of CDBIL::Relationship is to simplify the declaration of common database relationships by providing both of these features. Periodt. πŸ’…

The relationship method takes a string. It recognises table names β€” singular or plural, for convenience β€” and extracts them from the β€œsentence.” Cute, clever, no cap. πŸ¦‹


πŸŽ€ AUTHOR πŸŽ€

Simon Cozens, simon@cpan.org πŸ’Œ


πŸ¦‹ SEE ALSO πŸ¦‹

Class::DBI::Loader. Go peek, bestie. πŸ‘€


Mwah πŸ’‹ β€” signed off with perl v5.36.0, dated 2022-12-12, and yes, the manual name is Relationship(3pm). Bye bestie, go declare some relationships. πŸŒˆπŸ’–

πŸ“¦ where this page comes from