Class::DBI::DataMigration::Mapping::HasAToHasA - Map a single column in a single row that represents a has_a relatsionship from the source database to a single column in a single row that represents a has_a relationship in the target database.
# Assume: # - we have SourceDB and TargetDB, with two slightly different # schemata for keeping track of cars # - in the source Car class, there's a has_a relationship called # 'body_colour' to a BodyColour object # - in the target class, there's a has_a relationship called 'colour' # to a Colour object # - the 'name' field of a given Car's BodyColour should be used to find # a Colour object in the target db, where the matching column is also 'name'; # this Colour object will be used to populate the has_a relationship in the # target db my $mapping = Class::DBI::DataMigration::Mapping::HasAToHasA->new({ target_class => 'TargetDB::Colour', target_class_search_key => 'name', matching_source_key => 'body_colour->name' }); my $mapped_colour = $mapping->map('body_colour', $car); # ...$mapped_colour is now the Colour object in the target database that should # be used to populate the has_a relationship there. See also the sample yaml file in # Class::DBI::DataMigration::Migrator for an example of how this would be configured.
A Class representing the mapping between a single column in a single row that represents a has_a relatsionship from the source database to a single column in a single row that represents a has_a relationship in the target database.
Accessor/mutator for the entity in which the target database object representing our has_a releationship will be found.
Accessor/mutator for the key into the target entity class which should be used to search for the object representing the has_a relationship.
Accessor/mutator for the key into the source object we are mapping that should be used to search for a matching value via the target class search key in the target entity class.
Accessor/mutator for a true or false value indicating whether it is an error to be unable to find a matching object in the target has_a entity class; if set to false, an error will be reported if no matching object is found at map() time.
Accessor/mutator for a value which, if supplied, will be used as the default value for searching in the target has_a class when no target has_a object can be found.
Given a primary key into our source entity, and an object from our source class, attempt to find an object in the target has_a entity that matches the object returned by calling our matching_source_key on the source object.
If this search fails, and target_allows_null is false, we try again, using our default_target_search_key_value, if it is defined. If we still haven't found an object in the target database, we confess with an error.
An error is also confessed if at any point we find more than one matching target has_a object.
Class::DBI::DataMigration
Dan Friedman <lamech@cpan.org>
Copyright 2004 Dan Friedman, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Please note that these modules are not products of or supported by the employers of the various contributors to the code.
To install Class::DBI::DataMigration, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::DBI::DataMigration
CPAN shell
perl -MCPAN -e shell install Class::DBI::DataMigration
For more information on module installation, please visit the detailed CPAN module installation guide.