$me{$col} = shift @row;
}
}
- my $new = $self->{source}->result_class->inflate_result(\%me, \%pre);
+ my $new = $self->{source}->result_class->inflate_result(
+ $self->{source}, \%me, \%pre);
$new = $self->{attrs}{record_filter}->($new)
if exists $self->{attrs}{record_filter};
return $new;
return $_[0]->reset->next;
}
+=head2 update(\%values)
+
+Sets the specified columns in the resultset to the supplied values
+
+=cut
+
+sub update {
+ my ($self, $values) = @_;
+ die "Values for update must be a hash" unless ref $values eq 'HASH';
+ return $self->{source}->storage->update(
+ $self->{source}->from, $values, $self->{cond});
+}
+
+=head2 update_all(\%values)
+
+Fetches all objects and updates them one at a time. ->update_all will run
+cascade triggers, ->update will not.
+
+=cut
+
+sub update_all {
+ my ($self, $values) = @_;
+ die "Values for update must be a hash" unless ref $values eq 'HASH';
+ foreach my $obj ($self->all) {
+ $obj->set_columns($values)->update;
+ }
+ return 1;
+}
+
=head2 delete
-Deletes all elements in the resultset.
+Deletes the contents of the resultset from its result source.
=cut
sub delete {
my ($self) = @_;
- $_->delete for $self->all;
+ $self->{source}->storage->delete($self->{source}->from, $self->{cond});
return 1;
}
-*delete_all = \&delete; # Yeah, yeah, yeah ...
+=head2 delete_all
+
+Fetches all objects and deletes them one at a time. ->delete_all will run
+cascade triggers, ->delete will not.
+
+=cut
+
+sub delete_all {
+ my ($self) = @_;
+ $_->delete for $self->all;
+ return 1;
+}
=head2 pager
my ($self, $upd) = @_;
$self->throw( "Not in database" ) unless $self->in_storage;
my %to_update = $self->get_dirty_columns;
- return -1 unless keys %to_update;
+ return $self unless keys %to_update;
my $rows = $self->result_source->storage->update(
$self->result_source->from, \%to_update, $self->ident_condition);
if ($rows == 0) {
my $self = shift;
if (ref $self) {
$self->throw( "Not in database" ) unless $self->in_storage;
- #warn $self->_ident_cond.' '.join(', ', $self->_ident_values);
$self->result_source->storage->delete(
$self->result_source->from, $self->ident_condition);
$self->in_storage(undef);
- #$self->store_column($_ => undef) for $self->primary_columns;
- # Should probably also arrange to trash PK if auto
- # but if we do, post-delete cascade triggers fail :/
} else {
my $attrs = { };
if (@_ > 1 && ref $_[$#_] eq 'HASH') {
$attrs = { %{ pop(@_) } };
}
my $query = (ref $_[0] eq 'HASH' ? $_[0] : {@_});
- $self->storage->delete($self->_table_name, $query);
+ $self->result_source->resultset->search(@_)->delete;
}
return $self;
}
while (my ($col,$val) = each %$data) {
$self->set_column($col,$val);
}
+ return $self;
}
=head2 copy
=cut
+sub copy {
+ my ($self, $changes) = @_;
+ my $new = bless({ _column_data => { %{$self->{_column_data}}} }, ref $self);
+ $new->set_column($_ => $changes->{$_}) for keys %$changes;
+ return $new->insert;
+}
+
=head2 store_column
$obj->store_column($col => $val);
=head2 inflate_result
- Class->inflate_result(\%me, \%prefetch?)
+ Class->inflate_result($result_source, \%me, \%prefetch?)
Called by ResultSet to inflate a result from storage
=cut
sub inflate_result {
- my ($class, $me, $prefetch) = @_;
+ my ($class, $source, $me, $prefetch) = @_;
#use Data::Dumper; print Dumper(@_);
- my $new = bless({ _column_data => $me, _in_storage => 1 },
- ref $class || $class);
+ my $new = bless({ result_source => $source,
+ _column_data => $me,
+ _in_storage => 1
+ },
+ ref $class || $class);
my $schema;
PRE: foreach my $pre (keys %{$prefetch||{}}) {
my $rel_obj = $class->relationship_info($pre);
die "Can't prefetch non-eistant relationship ${pre}" unless $rel_obj;
- $schema ||= $new->result_source->schema;
+ $schema ||= $source->schema;
my $pre_class = $schema->class($rel_obj->{class});
- my $fetched = $pre_class->inflate_result(@{$prefetch->{$pre}});
+ my $fetched = $pre_class->inflate_result(
+ $schema->source($pre_class), @{$prefetch->{$pre}});
$class->throw("No accessor for prefetched $pre")
unless defined $rel_obj->{attrs}{accessor};
PRIMARY: foreach my $pri ($rel_obj->{class}->primary_columns) {
return $new;
}
-sub copy {
- my ($self, $changes) = @_;
- my $new = bless({ _column_data => { %{$self->{_column_data}}} }, ref $self);
- $new->set_column($_ => $changes->{$_}) for keys %$changes;
- return $new->insert;
-}
-
=head2 insert_or_update
$obj->insert_or_update