[Dbix-class] DBIx::Class::Helper::ResultSet::Random for Resultsets
only known at runtime
"José Diaz Seng"
josediazseng at gmx.de
Tue Nov 6 16:45:54 GMT 2012
o.k., I found a possible solution to my problem described in my last post,
> But later on I tried to use the rand function (note that I used an eval
> here too since I hoped the late evaluation would perhaps help):
> -----start code----
> my $random_row;
> eval '$random_row = $dbic_schema->resultset("T")->rand->single;';
> $error = $@;
> croak $error if $@;
> -----end code----
> The error message I got was
> "Can't locate object method "rand" via package "DBIx::Class::ResultSet" at..."
> Do you know how can I turn $dbic_schema->resultset("T") into an object of type
> DBIC::Schema::ResultSet::T or if there is a better approach?
One can of course say instead
my $resultset = $dbic_schema->resultset("T");
bless $resultset, 'DBIC::Schema::ResultSet::T';
my $row = $resultset->rand->single;
and this works fine.
It still feels like a hack, though. Do you have a better idea?
More information about the DBIx-Class