Re: arbitrary table names - best practice?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: arbitrary table names - best practice?

michael reddick


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 = __PACKAGE__->source('Foo'); # get the resultsource created by the Foo class

foreach my $i (0 .. $max_table_numer) {
 my $numbered_source = $source->new($source);
 $numbered_source->table("foo_${i}");
 __PACKAGE__->register_source("Foo_${i}" => $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.


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: arbitrary table names - best practice?

Bhawna Bhati
Michael,

I have same problem as is mentioned here. Can you please explain you answer
in more detail.


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...