DBIx::Class::Row - Basic row methods
This class is responsible for defining and doing basic operations on rows derived from DBIx::Class::ResultSource objects.
my $obj = My::Class->new($attrs);
Creates a new row object from column => value mappings passed as a hash ref
Passing an object, or an arrayref of objects as a value will call "set_from_related" in DBIx::Class::Relationship::Base for you. When passed a hashref or an arrayref of hashrefs as the value, these will be turned into objects via new_related, and treated as if you had passed objects.
For a more involved explanation, see "create" in DBIx::Class::ResultSet.
$obj->insert;
Inserts an object into the database if it isn't already in there. Returns the object itself. Requires the object's result source to be set, or the class to have a result_source_instance method. To insert an entirely new object into the database, use create (see "create" in DBIx::Class::ResultSet).
create
To fetch an uninserted row object, call new on a resultset.
This will also insert any uninserted, related objects held inside this one, see "create" in DBIx::Class::ResultSet for more details.
$obj->in_storage; # Get value $obj->in_storage(1); # Set value
Indicates whether the object exists as a row in the database or not. This is set to true when "find" in DBIx::Class::ResultSet, "create" in DBIx::Class::ResultSet or "insert" in DBIx::Class::ResultSet are used.
Creating a row object using "new" in DBIx::Class::ResultSet, or calling "delete" on one, sets it to false.
$obj->update \%columns?;
Must be run on an object that is already in the database; issues an SQL UPDATE query to commit any changes to the object to the database if required.
Also takes an options hashref of column_name => value> pairs to update first. But be aware that the hashref will be passed to set_inflated_columns, which might edit it in place, so dont rely on it being the same after a call to update. If you need to preserve the hashref, it is sufficient to pass a shallow copy to update, e.g. ( { %{ $href } } )
column_name => value> pairs
set_inflated_columns
update
$obj->delete
Deletes the object from the database. The object is still perfectly usable, but ->in_storage() will now return 0 and the object must reinserted using ->insert() before ->update() can be used on it. If you delete an object in a class with a has_many relationship, all the related objects will be deleted as well. To turn this behavior off, pass cascade_delete => 0 in the $attr hashref. Any database-level cascade or restrict will take precedence over a DBIx-Class-based cascading delete. See also "delete" in DBIx::Class::ResultSet.
->in_storage()
->insert()
->update()
has_many
cascade_delete => 0
$attr
my $val = $obj->get_column($col);
Returns a raw column value from the row object, if it has already been fetched from the database or set by an accessor.
If an inflated value has been set, it will be deflated and returned.
if ( $obj->has_column_loaded($col) ) { print "$col has been loaded from db"; }
Returns a true value if the column value has been loaded from the database (or set locally).
my %data = $obj->get_columns;
Does get_column, for all loaded column values at once.
get_column
my %data = $obj->get_dirty_columns;
Identical to get_columns but only returns those that have been changed.
my %inflated_data = $obj->get_inflated_columns;
Similar to get_columns but objects are returned for inflated columns instead of their raw non-inflated values.
$obj->set_column($col => $val);
Sets a raw column value. If the new value is different from the old one, the column is marked as dirty for when you next call $obj->update.
If passed an object or reference, this will happily attempt store the value, and a later insert/update will try and stringify/numify as appropriate.
my $copy = $orig->set_columns({ $col => $val, ... });
Sets more than one column value at once.
my $copy = $orig->set_inflated_columns({ $col => $val, $rel => $obj, ... });
Sets more than one column value at once, taking care to respect inflations and relationships if relevant. Be aware that this hashref might be edited in place, so dont rely on it being the same after a call to set_inflated_columns. If you need to preserve the hashref, it is sufficient to pass a shallow copy to set_inflated_columns, e.g. ( { %{ $href } } )
my $copy = $orig->copy({ change => $to, ... });
Inserts a new row with the specified changes. If the row has related objects in a has_many then those objects may be copied too depending on the cascade_copy relationship attribute.
cascade_copy
$obj->store_column($col => $val);
Sets a column value without marking it as dirty.
Class->inflate_result($result_source, \%me, \%prefetch?)
Called by ResultSet to inflate a result from storage
$obj->update_or_insert
Updates the object if it's already in the database, according to "in_storage", else inserts it.
$obj->insert_or_update
Alias for "update_or_insert"
my @changed_col_names = $obj->is_changed(); if ($obj->is_changed()) { ... }
In array context returns a list of columns with uncommited changes, or in scalar context returns a true value if there are uncommitted changes.
if ($obj->is_column_changed('col')) { ... }
Returns a true value if the column has uncommitted changes.
my $resultsource = $object->result_source;
Accessor to the ResultSource this object was created from
$column_info = { .... }; $class->register_column($column_name, $column_info);
Registers a column on the class. If the column_info has an 'accessor' key, creates an accessor named after the value if defined; if there is no such key, creates an accessor with the same name as the column
The column_info attributes are described in "add_columns" in DBIx::Class::ResultSource
See Schema's throw_exception.
Returns the primary key(s) for a row. Can't be called as a class method. Actually implemented in DBIx::Class::PK
Re-selects the row from the database, losing any changes that had been made.
This method can also be used to refresh from storage, retrieving any changes made since the row was last read from storage. Actually implemented in DBIx::Class::PK
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.