logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Class::DBI::Loader::Relationship - Easier relationship specification in CDBI::L

Author

       Simon Cozens, "simon@cpan.org"

Description

       This module acts as a mix-in, adding the "relationship" method to "Class::DBI::Loader". Since
       "Class::DBI::Loader" knows how to map between table names and class names, there ought to be no need to
       replicate the names.

       In addition, it is common (but not universal) to want reverse relationships defined for has-many
       relationships, and for has-a relationships to be defined for the linkages surrounding a many-to-many
       table.

       The aim of "CDBIL::Relationship" is to simplify the declaration of common database relationships by
       providing both of these features.

       The "relationship" takes a string. It recognises table names (singular or plural, for convenience) and
       extracts them from the "sentence".

Name

       Class::DBI::Loader::Relationship - Easier relationship specification in CDBI::L

See Also

       Class::DBI::Loader.

perl v5.36.0                                       2022-12-12                                  Relationship(3pm)

Synopsis

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

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

       Now instead of saying

           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' ]);

       Just say

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

See Also