[Dbix-class] arbitrary table names - best practice?

michael reddick michael.reddick at gmail.com
Thu Feb 12 16:12:35 GMT 2009


>
> I don't think that's what you want.
>
> What you want is one *result source* per table, but only one class. So.
>
> Create a class My::Schema::Foo as normal. set ->table to '__VIRTUAL__' or
> something.
>
> Then, after load_classes()/load_namespaces(),
>
> my $source =3D __PACKAGE__->source('Foo'); # get the resultsource created=
 by
> the Foo class
>
> foreach my $i (0 .. $max_table_numer) {
>  my $numbered_source =3D $source->new($source);
>  $numbered_source->table("foo_${i}");
>  __PACKAGE__->register_source("Foo_${i}" =3D> $numbered_source);
> }
>
> Then your code can just do $schema->resultset("Foo_123") or whatever.
>
>
Just fyi in case someone else tries to do this... This works except you have
to replace ->table with ->name.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090212/53a=
b175c/attachment.htm


More information about the DBIx-Class mailing list