Sometimes when working with DBIX::Class whenever you create a record
in a table, you want to create another record in a corresponding
table. Are you going to go and sift through your code base looking for
all code that writes to the table? Not when you can change your schema
class to handle the action for you.
In order to do this we can override the insert method. This example is
taken from DBIx::Class::Manual::Cookbook :
sub insert {
my ( $self, @args ) = @_;
$self->next::method(@args);
$self->create_related ('cds', \%initial_cd_data );
return $self;
}
You see above that next::method is called and then a record is
inserted in a related field. Be aware that you need to call
next::method before you call create so that you write the original
call before making the new one.