Fix create() in the same way as update() so it throws out the new values and
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / LazyLoading.pm
index 0b6691b..e8ffbcc 100644 (file)
@@ -20,14 +20,38 @@ sub update {
     my @dirty_columns = keys %{$self->{_dirty_columns}};
     
     my $ret = $self->next::method(@_);
-    
-    delete $self->{_column_data}{$_}     for @dirty_columns;
-    delete $self->{_inflated_column}{$_} for @dirty_columns;
+    $self->_clear_column_data(@dirty_columns);
     
     return $ret;
 }
 
 
+# And again for create
+sub create {
+    my $class = shift;
+    my($data) = @_;
+    
+    my @columns = keys %$data;
+    
+    my $obj = $class->next::method(@_);
+    return $obj unless defined $obj;
+    
+    my %primary_cols = map { $_ => 1 } $class->primary_columns;
+    my @data_cols = grep !$primary_cols{$_}, @columns;
+    $obj->_clear_column_data(@data_cols);
+
+    return $obj;
+}
+
+
+sub _clear_column_data {
+    my $self = shift;
+    
+    delete $self->{_column_data}{$_}     for @_;
+    delete $self->{_inflated_column}{$_} for @_;
+}
+
+
 sub get_column {
   my ($self, $col) = @_;
   if ((ref $self) && (!exists $self->{'_column_data'}{$col})