DBIx::...inTable(3pm)
π DBIx::Class::Helper::Row::JoinTable π
hey bestie π«Ά welcome to DBIx::...inTable(3pm), straight outta the User Contributed Perl Documentation. it's giving "join tables but make it effortless" and honestly? obsessed.
β¨ NAME β¨
DBIx::Class::Helper::Row::JoinTable β easily set up join tables with DBIx::Class. that's the whole vibe. π
πΈ SYNOPSIS πΈ
okay so picture this: you've got a join table and you want it set up with zero suffering. look:
package MyApp::Schema::Result::Foo_Bar;
__PACKAGE__->load_components(qw{Helper::Row::JoinTable Core});
__PACKAGE__->join_table({
left_class => 'Foo',
left_method => 'foo',
right_class => 'Bar',
right_method => 'bar',
});
# the above is the same as:
__PACKAGE__->table('Foo_Bar');
__PACKAGE__->add_columns(
foo_id => {
data_type => 'integer',
is_nullable => 0,
is_numeric => 1,
},
bar_id => {
data_type => 'integer',
is_nullable => 0,
is_numeric => 1,
},
);
$self->set_primary_key(qw{foo_id bar_id});
__PACKAGE__->belongs_to( foo => 'MyApp::Schema::Result::Foo' 'foo_id');
__PACKAGE__->belongs_to( bar => 'MyApp::Schema::Result::Bar' 'bar_id');
likeβ¦ that's it. that's the whole thing. the second block is literally what the first block does behind the scenes β same energy, just longer π¦
and if you're running DBIx::Class::Candy, it gets even cuter:
package MyApp::Schema::Result::Foo_Bar;
use DBIx::Class::Candy -components => ['Helper::Row::JoinTable'];
join_table {
left_class => 'Foo',
left_method => 'foo',
right_class => 'Bar',
right_method => 'bar',
};
periodt. π
π METHODS π
all these methods take a configuration hashref, and the hashref looks exactly like this:
{
left_class => 'Foo',
left_method => 'foo', # see NOTE
left_method_plural => 'foos', # see NOTE, not required, used for
# many_to_many rel name in right_class
# which is not generated by default
right_class => 'Bar',
right_method => 'bar', # see NOTE
right_method_plural => 'bars', # see NOTE, not required, used for
# many_to_many rel name in left_class
# which is not generated by default
namespace => 'MyApp', # default is guessed via *::Foo
self_method => 'foobars', # not required, used for setting the name of the
# join table's relationship in a has_many
# which is not generated by default
}
π join_table
this is the method. the main character. π the one you probably actually want.
it will set your table, add columns, set the primary key, and set up the relationships. all four things. in one go. slay.
π add_join_columns
adds two non-nullable integer fields, named ${left_method}_id and ${right_method}_id respectively. no notes. β¨
π generate_has_manys
installs methods into left_class and right_class so you can get to the join table. those methods get named whatever you passed into the configuration hashref as self_method. π«
π generate_many_to_manys
installs many_to_many methods into left_class and right_class. the names come from your config hashref: left_method_plural gives the name for the right_class, and right_method_plural gives the name for the left_class. yes, it's crossed over like that, and yes, that's intentional. π₯
π generate_primary_key
sets ${left_method}_id and ${right_method}_id to be the primary key. two columns, one key, iconic. π
π generate_relationships
this adds relationships to ${namespace}::Schema::Result::$left_class and ${namespace}::Schema::Result::$left_class respectively.
π set_table
this method sets the table to ${left_class}_${right_class}. simple as. π
π CANDY EXPORTS π
if you use this component together with DBIx::Class::Candy, it will export:
join_tablegenerate_primary_keygenerate_has_manysgenerate_many_to_manysgenerate_relationshipsset_tableadd_join_columns
π NOTE
this module uses (an internal fork of) String::CamelCase to default the method names, and it uses Lingua::EN::Inflect for pluralization. iykyk. π§
π¦ CHANGES BETWEEN RELEASES π¦
β Changes since 0.*
originally this module would use
data_type => 'integer',
is_nullable => 0,
is_numeric => 1,
for all joining columns. now? it infers data_type, is_nullable, is_numeric, and extra from the foreign tables instead. glow-up fr fr. π
π AUTHOR π
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2024 by Arthur Axel "fREW" Schmidt.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole page bestie, thanks for reading to the end π«Ά this was DBIx::...inTable(3pm) as shipped with perl v5.40.0, dated 2024-11-16. go forth and build your join tables, you've got this. πβ¨πΈ
π¦ where this page comes from
- debian trixie: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms