NAME

DBIx::Class::Schema::Loader::RelBuilder - Builds relationships for DBIx::Class::Schema::Loader

SYNOPSIS

See DBIx::Class::Schema::Loader

DESCRIPTION

This class builds relationships for DBIx::Class::Schema::Loader. This is module is not (yet) for external use.

METHODS

new

Arguments: schema_class (scalar), fk_info (hashref) [, inflect_map ]

$schema_class should be a schema class name, where the source classes have already been set up and registered. Column info, primary key, and unique constraints will be drawn from this schema for all of the existing source monikers.

The fk_info hashref's contents should take the form:

{
    TableMoniker => [
        {
            local_columns => [ 'col2', 'col3' ],
            remote_columns => [ 'col5', 'col7' ],
            remote_moniker => 'AnotherTableMoniker',
        },
        # ...
    ],
    AnotherTableMoniker => [
        # ...
    ],
    # ...
}

And inflect_map is documented at DBIx::Class::Schema::Loader, either a coderef or a hashref which can override the default Lingua::EN::Inflect::Number pluralizations. Used in generating relationship names.

generate_code

This method will return the generated relationships as a hashref per table moniker, containing an arrayref of code strings which can be "eval"-ed in the context of the source class, like:

{
    'Some::Source::Class' => [
        "belongs_to( col1 => 'AnotherTableMoniker' )",
        "has_many( anothers => 'AnotherTableMoniker', 'col15' )",
    ],
    'Another::Source::Class' => [
        # ...
    ],
    # ...
}
        

You might want to use this in building an on-disk source class file, by adding each string to the appropriate source class file, prefixed by __PACKAGE__->.

setup_rels

Arguments: debug (boolean)

Basically, calls #generate_code, and then evals the generated code in the appropriate class context, all in one fell swoop. This is how Schema::Loader uses this class. Will dump the strings to stderr along the way if $debug is set.