Skip to content

Instantly share code, notes, and snippets.

@semifor
Created December 27, 2016 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semifor/0ff9133b48d9803f39df2fa074bf48f3 to your computer and use it in GitHub Desktop.
Save semifor/0ff9133b48d9803f39df2fa074bf48f3 to your computer and use it in GitHub Desktop.

Handling multiple tables with the same schema

From mst irc://irc.perl.org#dbix-class, 2016-12-27.

Registering those tables

my $source = $schema->source('UserData');
my $new_source = $source->new(%$source, name => "user_data_${user_id}");
$schema->register_source('UserData_'.$user_id => $new_source);
my $rs = $schema->resultset('UserData_'.$user_id);

Per request (unregistered)

my $request_schema = $global_schema->clone;
$request_schema->source('UserData')->name("user_data_${user_id}");
# just use $request_schema and let it go away at the end of the request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment