rename Change to ChangeLog to avoid reserved word problem
Yuval Kogman [Wed, 30 Jul 2008 03:47:27 +0000 (03:47 +0000)]
lib/DBIx/Class/Journal.pm
lib/DBIx/Class/Schema/Journal/DB.pm
lib/DBIx/Class/Schema/Journal/DB/AuditHistory.pm
lib/DBIx/Class/Schema/Journal/DB/AuditLog.pm
lib/DBIx/Class/Schema/Journal/DB/ChangeLog.pm [moved from lib/DBIx/Class/Schema/Journal/DB/Change.pm with 87% similarity]

index b93987c..8c3a57d 100644 (file)
@@ -69,8 +69,8 @@ sub delete
             $self->throw_exception( "No audit_log entry found for ".ref($self) . " item $pri" ) if(!$alentry);
              
             ## bulk_update doesnt do "create new item on update of rel-accessor with hashref, yet
-            my $change = $self->result_source->schema->_journal_schema->resultset('Change')->create({ changeset_id => $self->result_source->schema->_journal_schema->current_changeset });
-            $alentry->delete_id($change->ID);
+            my $change = $self->result_source->schema->_journal_schema->resultset('ChangeLog')->create({ changeset_id => $self->result_source->schema->_journal_schema->current_changeset });
+            $alentry->delete_id($change->id);
             $alentry->update();
         }
     }
index 4f31cb1..1f247fb 100644 (file)
@@ -7,23 +7,32 @@ __PACKAGE__->mk_group_accessors( simple => 'current_user' );
 __PACKAGE__->mk_group_accessors( simple => 'current_session' );
 __PACKAGE__->mk_group_accessors( simple => '_current_changeset_container' );
 
+DBIx::Class::Schema::Journal::DB->load_classes(qw/
+                                               ChangeSet
+                                               ChangeLog
+                                               AuditLog
+                                               AuditHistory
+                                               /);
+
+
+sub _current_changeset {
+    my $self = shift;
+    my $ref = $self->_current_changeset_container;
+    $ref && $ref->{changeset};
+}
+
 # this is for localization of the current changeset
 sub current_changeset {
     my ( $self, @args ) = @_;
 
-    $self->throw_error("setting current_changeset is not supported, use txn_do to create a new changeset") if @args;
+    $self->throw_exception("setting current_changeset is not supported, use txn_do to create a new changeset") if @args;
 
-    my $ref = $self->_current_changeset_container;
+    my $id = $self->_current_changeset;
 
-    return $ref && $ref->{changeset};
-}
+    $self->throw_exception("Can't call current_changeset outside of a transaction") unless $id;
 
-DBIx::Class::Schema::Journal::DB->load_classes(qw/
-                                               ChangeSet
-                                               Change
-                                               AuditLog
-                                               AuditHistory
-                                               /);
+    return $id;
+}
 
 sub journal_create_changeset {
     my ( $self, @args ) = @_;
index dbfacf1..d19d11b 100644 (file)
@@ -8,7 +8,7 @@ __PACKAGE__->add_columns(
                                data_type => 'integer',
                                is_nullable => 0,
                            });
-__PACKAGE__->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::Change', 'change_id');
+__PACKAGE__->belongs_to('change', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'change_id');
 
 sub new
 {
index a28af3d..8938045 100644 (file)
@@ -21,8 +21,8 @@ __PACKAGE__->add_columns(
                            });
 __PACKAGE__->set_primary_key('ID');
 
-  __PACKAGE__->belongs_to('created', 'DBIx::Class::Schema::Journal::DB::Change', 'create_id');
-  __PACKAGE__->belongs_to('deleted', 'DBIx::Class::Schema::Journal::DB::Change', 'delete_id');
+  __PACKAGE__->belongs_to('created', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'create_id');
+  __PACKAGE__->belongs_to('deleted', 'DBIx::Class::Schema::Journal::DB::ChangeLog', 'delete_id');
 
 sub new
 {
similarity index 87%
rename from lib/DBIx/Class/Schema/Journal/DB/Change.pm
rename to lib/DBIx/Class/Schema/Journal/DB/ChangeLog.pm
index 519973a..d3ed0ef 100644 (file)
@@ -1,13 +1,13 @@
-package DBIx::Class::Schema::Journal::DB::Change;
+package DBIx::Class::Schema::Journal::DB::ChangeLog;
 
 use base 'DBIx::Class';
 
 # __PACKAGE__->load_components(qw/Core/);
 __PACKAGE__->load_components(qw/Ordered Core/);
-__PACKAGE__->table('change');
+__PACKAGE__->table('change_log');
 
 __PACKAGE__->add_columns(
-                         ID => {
+                         id => {
                              data_type => 'integer',
                              is_auto_increment => 1,
                              is_primary_key => 1,
@@ -25,7 +25,7 @@ __PACKAGE__->add_columns(
                          );
 
 
-__PACKAGE__->set_primary_key('ID');
+__PACKAGE__->set_primary_key('id');
 __PACKAGE__->add_unique_constraint('setorder', [ qw/changeset_id order_in/ ]);
 __PACKAGE__->belongs_to('changeset', 'DBIx::Class::Schema::Journal::DB::ChangeSet', 'changeset_id');