NAME

DBIO::Generate::Relationships - Relationship inference for DBIO::Generate

VERSION

version 0.900004

METHODS

new

my $r = DBIO::Generate::Relationships->new(
  inflect_plural       => \%plural_map,    # or undef
  inflect_singular     => \%singular_map,  # or undef
  rel_name_map         => \%map_or_coderef,
  rel_collision_map    => \%map,           # default {}
  allow_extra_m2m_cols => 0,               # default 0
  quiet                => 0,               # default 0
);

Builds the relationship inferrer. DBIO::Generate constructs one per run, passing its own options of the same names through. inflect_plural / inflect_singular are hashrefs of explicit overrides consulted before Lingua::EN::Inflect::Phrase; rel_name_map is a hashref (old name to new name) or a coderef receiving { name, type, local_moniker, local_columns, remote_moniker, remote_columns } and returning the new name (undef keeps the old one). allow_extra_m2m_cols follows "allow_extra_m2m_cols" in DBIx::Class::Schema::Loader::Base: a table is a link table -- and gets a many_to_many on its first side -- when it carries exactly two belongs_to relationships and its primary key equals the union of their columns; with allow_extra_m2m_cols false (the default) it must also have no column beyond that key, with it true extra columns are allowed. The flag only ever adds bridges (it used to suppress all of them). rel_collision_map and quiet are stored for DBIO::Generate parity but not consulted by the inference itself.

generate_code

my $code = $r->generate_code($tables, $class_for, $pk_for, $cols_for);

Takes an arrayref of [ $moniker, \@fk_info, \@uniq_info ]. Each FK info hashref must have remote_moniker (not remote_table). class_for maps moniker → class name string. pk_for maps moniker → PK column arrayref. cols_for (optional) maps moniker → column arrayref; it is what lets a link table be recognised as having no extra columns. A table without an entry is bridged only under allow_extra_m2m_cols.

Returns hashref { $moniker => [ { method, args, extra }, ... ] }.

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.