NAME
DBIx::Class::ResultSource - Result source object
SYNOPSIS
DESCRIPTION
A ResultSource is a component of a schema from which results can be directly retrieved, most usually a table (see DBIx::Class::ResultSource::Table)
METHODS
add_columns
$table->add_columns(qw/col1 col2 col3/);
$table->add_columns('col1' => \%col1_info, 'col2' => \%col2_info, ...);
Adds columns to the result source. If supplied key => hashref pairs uses the hashref as the column_info for that column.
add_column
$table->add_column('col' => \%info?);
Convenience alias to add_columns
has_column
if ($obj->has_column($col)) { ... }
Returns 1 if the source has a column of this name, 0 otherwise.
column_info
my $info = $obj->column_info($col);
Returns the column metadata hashref for a column.
columns
my @column_names = $obj->columns;
ordered_columns
my @column_names = $obj->ordered_columns;
Like columns(), but returns column names using the order in which they were originally supplied to add_columns().
set_primary_key(@cols)
Defines one or more columns as primary key for this source. Should be called after add_columns
.
primary_columns
Read-only accessor which returns the list of primary keys.
from
Returns an expression of the source to be supplied to storage to specify retrieval from this source; in the case of a database the required FROM clause contents.
storage
Returns the storage handle for the current schema
add_relationship
$source->add_relationship('relname', 'related_source', $cond, $attrs);
The relation name can be arbitrary, but must be unique for each relationship attached to this result source. 'related_source' should be the name with which the related result source was registered with the current schema (for simple schemas this is usally either Some::Namespace::Foo or just Foo)
The condition needs to be an SQL::Abstract-style representation of the join between the tables. For example, if you're creating a rel from Foo to Bar,
{ 'foreign.foo_id' => 'self.id' }
will result in the JOIN clause
foo me JOIN bar bar ON bar.foo_id = me.id
You can specify as many foreign => self mappings as necessary.
Valid attributes are as follows:
- join_type
-
Explicitly specifies the type of join to use in the relationship. Any SQL join type is valid, e.g.
LEFT
orRIGHT
. It will be placed in the SQL command immediately beforeJOIN
. - proxy
-
An arrayref containing a list of accessors in the foreign class to proxy in the main class. If, for example, you do the following:
__PACKAGE__->might_have(bar => 'Bar', undef, { proxy => qw[/ margle /] });
Then, assuming Bar has an accessor named margle, you can do:
my $obj = Foo->find(1); $obj->margle(10); # set margle; Bar object is created if it doesn't exist
- accessor
-
Specifies the type of accessor that should be created for the relationship. Valid values are
single
(for when there is only a single related object),multi
(when there can be many), andfilter
(for when there is a single related object, but you also want the relationship accessor to double as a column accessor). Formulti
accessors, an add_to_* method is also created, which callscreate_related
for the relationship.
relationships()
Returns all valid relationship names for this source
relationship_info($relname)
Returns the relationship information for the specified relationship name
has_relationship($rel)
Returns 1 if the source has a relationship of this name, 0 otherwise.
resolve_join($relation)
Returns the join structure required for the related result source
resolve_condition($cond, $rel, $alias|$object)
Resolves the passed condition to a concrete query fragment. If given an alias, returns a join condition; if given an object, inverts that object to produce a related conditional from that object.
related_source($relname)
Returns the result source for the given relationship
AUTHORS
Matt S. Trout <mst@shadowcatsystems.co.uk>
LICENSE
You may distribute this code under the same terms as Perl itself.