use base qw/DBIx::Class/;
-use DBIx::Class::Exception;
use Scalar::Util 'blessed';
use List::Util 'first';
use Try::Tiny;
use namespace::clean;
+__PACKAGE__->mk_group_accessors ( simple => [ in_storage => '_in_storage' ] );
+
=head1 NAME
DBIx::Class::Row - Basic row methods
my ($class, $attrs) = @_;
$class = ref $class if ref $class;
- my $new = bless { _column_data => {} }, $class;
+ my $new = bless { _column_data => {}, _in_storage => 0 }, $class;
if ($attrs) {
$new->throw_exception("attrs must be a hashref")
next;
}
}
- $new->throw_exception("No such column $key on $class")
+ $new->throw_exception("No such column '$key' on $class")
unless $class->has_column($key);
$new->store_column($key => $attrs->{$key});
}
A column accessor method is created for each column, which is used for
getting/setting the value for that column.
-The actual method name is based on the L<accessor|DBIx::Class::ResultSource/accessor>
-name given in the table definition. Like L</set_column>, this will
-not store the data until L</insert> or L</update> is called on the row.
+The actual method name is based on the
+L<accessor|DBIx::Class::ResultSource/accessor> name given during the
+L<Result Class|DBIx::Class::Manual::ResultClass> L<column definition
+|DBIx::Class::ResultSource/add_columns>. Like L</set_column>, this
+will not store the data in the database until L</insert> or L</update>
+is called on the row.
=head2 insert
entirely new row into the database, use L<DBIx::Class::ResultSet/create>.
To fetch an uninserted result object, call
-L<new|DBIx::Class::ResultSet/new> on a resultset.
+L<new_result|DBIx::Class::ResultSet/new_result> on a resultset.
This will also insert any uninserted, related objects held inside this
one, see L<DBIx::Class::ResultSet/create> for more details.
L<DBIx::Class::ResultSet/create> or L<DBIx::Class::ResultSet/insert>
are used.
-Creating a result object using L<DBIx::Class::ResultSet/new>, or calling
-L</delete> on one, sets it to false.
+Creating a result object using L<DBIx::Class::ResultSet/new_result>, or
+calling L</delete> on one, sets it to false.
-=cut
-
-sub in_storage {
- my ($self, $val) = @_;
- $self->{_in_storage} = $val if @_ > 1;
- return $self->{_in_storage} ? 1 : 0;
-}
=head2 update
);
delete $self->{_column_data_in_storage};
- $self->in_storage(undef);
+ $self->in_storage(0);
}
else {
my $rsrc = try { $self->result_source_instance }
really changed.
=cut
+
sub make_column_dirty {
my ($self, $column) = @_;
sub inflate_result {
my ($class, $source, $me, $prefetch) = @_;
- $source = $source->resolve
- if $source->isa('DBIx::Class::ResultSourceHandle');
-
my $new = bless
{ _column_data => $me, _result_source => $source },
ref $class || $class
foreach my $pre (keys %{$prefetch||{}}) {
- my (@pre_vals, $is_multi);
- if (ref $prefetch->{$pre}[0] eq 'ARRAY') {
- $is_multi = 1;
- @pre_vals = @{$prefetch->{$pre}};
- }
- else {
- @pre_vals = $prefetch->{$pre};
- }
-
- my $pre_source = try {
- $source->related_source($pre)
- }
- catch {
- $class->throw_exception(sprintf
+ my @pre_vals;
+ @pre_vals = (ref $prefetch->{$pre}[0] eq 'ARRAY')
+ ? @{$prefetch->{$pre}} : $prefetch->{$pre}
+ if @{$prefetch->{$pre}||[]};
- "Can't inflate manual prefetch into non-existent relationship '%s' from '%s', "
- . "check the inflation specification (columns/as) ending in '%s.%s'.",
-
- $pre,
- $source->source_name,
- $pre,
- (keys %{$pre_vals[0][0]})[0] || 'something.something...',
- );
- };
+ my $pre_source = $source->related_source($pre);
my $accessor = $source->relationship_info($pre)->{attrs}{accessor}
- or $class->throw_exception("No accessor type declared for prefetched $pre");
-
- if (! $is_multi and $accessor eq 'multi') {
- $class->throw_exception("Manual prefetch (via select/columns) not supported with accessor 'multi'");
- }
+ or $class->throw_exception("No accessor type declared for prefetched relationship '$pre'");
my @pre_objects;
for my $me_pref (@pre_vals) {
- # FIXME - this should not be necessary
- # the collapser currently *could* return bogus elements with all
- # columns set to undef
- my $has_def;
- for (values %{$me_pref->[0]}) {
- if (defined $_) {
- $has_def++;
- last;
- }
- }
- next unless $has_def;
+ # FIXME SUBOPTIMAL - the new row parsers can very well optimize
+ # this away entirely, and *never* return such empty rows.
+ # For now we maintain inflate_result API backcompat, see
+ # t/resultset/inflate_result_api.t
+ next unless defined first { defined $_ } values %{$me_pref->[0]};
- push @pre_objects, $pre_source->result_class->inflate_result(
- $pre_source, @$me_pref
- );
+ push @pre_objects, $pre_source->result_class->inflate_result(
+ $pre_source, @$me_pref
+ );
}
if ($accessor eq 'single') {