DBIx::Class::ResultSource - Result source object
A ResultSource is a component of a schema from which results can be directly retrieved, most usually a table (see DBIx::Class::ResultSource::Table)
$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.
$table->add_column('col' => \%info?);
Convenience alias to add_columns
if ($obj->has_column($col)) { ... }
Returns 1 if the source has a column of this name, 0 otherwise.
my $info = $obj->column_info($col);
Returns the column metadata hashref for a column.
my @column_names = $obj->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().
Defines one or more columns as primary key for this source. Should be called after add_columns.
add_columns
Read-only accessor which returns the list of primary keys.
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.
Returns the storage handle for the current schema
$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:
Explicitly specifies the type of join to use in the relationship. Any SQL join type is valid, e.g. LEFT or RIGHT. It will be placed in the SQL command immediately before JOIN.
LEFT
RIGHT
JOIN
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
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), and filter (for when there is a single related object, but you also want the relationship accessor to double as a column accessor). For multi accessors, an add_to_* method is also created, which calls create_related for the relationship.
single
multi
filter
create_related
Returns all valid relationship names for this source
Returns the relationship information for the specified relationship name
Returns 1 if the source has a relationship of this name, 0 otherwise.
Returns the join structure required for the related result source
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.
Returns the result source for the given relationship
Matt S. Trout <mst@shadowcatsystems.co.uk>
You may distribute this code under the same terms as Perl itself.
To install DBIx::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class
CPAN shell
perl -MCPAN -e shell install DBIx::Class
For more information on module installation, please visit the detailed CPAN module installation guide.