Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@perlDreamer
Created March 3, 2010 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlDreamer/321187 to your computer and use it in GitHub Desktop.
Save perlDreamer/321187 to your computer and use it in GitHub Desktop.
sub write {
my $self = shift;
$self->lastModified(time());
my $db = $self->session->db;
my %data_by_table = ();
PROPERTY: foreach my $property_name ($self->meta->get_all_property_list) {
my $property = $self->meta->find_attribute_by_name($property_name);
my $tableName = $property->tableName;
my $value = $self->$property_name;
push @{ $data_by_table{$tableName}->{NAMES} }, $property_name;
push @{ $data_by_table{$tableName}->{VALUES} }, $value;
}
CLASS: foreach my $tableName (keys %data_by_table) {
my $table = $db->quoteIdentifier($tableName);
my @values = @{ $data_by_table{$tableName}->{VALUES} };
my @columnNames = map { $db->quoteIdentifier($_).'=?' } @{ $data_by_table{$tableName}->{NAMES}};
push @values, $self->getId, $self->revisionDate;
$db->write("update ".$table." set ".join(",",@columnNames)." where assetId=? and revisionDate=?",\@values);
}
# update the asset's size, which also purges the cache.
$self->setSize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment