Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
sub write {
my $self = shift;
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.