NAME

DBIx::QuickORM::Join - A query source built from joined tables.

DESCRIPTION

A source (see DBIx::QuickORM::Role::Source) representing one or more tables joined together. Each component table is given a short alias; the primary source is the first component, and additional tables are added with the join / left_join / right_join / inner_join methods, each of which returns a clone of the join with the new component added.

The join produces aliased SQL via source_db_moniker and aliased fetch fields via fields_to_fetch, and can fracture a flat fetched row back into per-alias data with fracture. Joins have no primary key and are not directly cachable.

SYNOPSIS

my $join = DBIx::QuickORM::Join->new(
    schema         => $schema,
    primary_source => $table,
);

my $joined = $join->left_join($link);

ATTRIBUTES

schema

The schema the joined tables belong to.

primary_source

The first/anchor table of the join.

join_as

Internal alias generator state (the next alias to hand out).

row_class

Row class used for fetched rows; defaults to DBIx::QuickORM::Join::Row.

order

Arrayref of component aliases in join order.

lookup

Hashref mapping a table's db moniker to the aliases it has been joined as.

components

Hashref mapping each alias to its component spec (table, link, from, type).

PUBLIC METHODS

$parts = $join->fracture(\%row)

Split a flat fetched row (with alias.field keys) into an arrayref of per-component pieces, one per alias that has any non-null value. Each piece carries the component source, its data, alias, and link.

$copy = $join->clone(%overrides)

Return a shallow copy of the join with the order, lookup, and components containers duplicated so the copy can be extended independently.

$ref = $join->source_db_moniker

Return a scalar reference to the SQL FROM fragment for the join, including each aliased table and its ON conditions.

($from, $table, $field) = $join->_field_source($proto, %params)

Resolve a alias.field (or bare field) proto into its alias, table, and field name. Croaks if the field cannot be resolved unless no_fatal is set.

$type = $join->field_type($proto)
$affinity = $join->field_affinity($proto, $dialect)
$bool = $join->has_field($proto)

Delegate field type, affinity, and existence checks to the component table that owns the given alias.field (or bare field) proto.

$sql = $join->fields_to_fetch

Return a comma-joined list of aliased select expressions covering every component table's fetch fields, each aliased as "alias.field".

Return an arrayref of all links from every component table in the join.

$table = $join->from($alias_or_name)

Resolve an alias or table name to its component table. Croaks when a table name is ambiguous (joined more than once) or cannot be resolved.

%params = $join->_join_params(@args)

Normalize join arguments: a single argument is treated as the link, otherwise the arguments are taken as a key/value list.

$copy = $join->_join(%params)

Clone the join and add a new component for the given link, resolving its alias and source-of-join (from) and appending it to the order, lookup, and components. Returns the new join.

$copy = $join->join($link, ...)
$copy = $join->left_join($link, ...)
$copy = $join->right_join($link, ...)
$copy = $join->inner_join($link, ...)

Return a clone of the join with another table added via the given link. The named variants set the join type (plain, LEFT, RIGHT, INNER). A single argument is taken as the link; otherwise pass link, as, from, etc. as key/value pairs.

SOURCE

The source code repository for DBIx::QuickORM can be found at https://github.com/exodist/DBIx-QuickORM.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright Chad Granum <exodist7@gmail.com>.

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

See https://dev.perl.org/licenses/