[Dbix-class] Auto-generate random primary keys
Bernhard Graf
dbic at augensalat.de
Wed Mar 1 11:58:23 CET 2006
Matt S Trout wrote:
> On Tue, Feb 28, 2006 at 03:55:08PM +0100, Bernhard Graf wrote:
> > Hi,
> >
> > I just started playing around with DBIC.
> >
> > Some tables in my db have random primary keys created by eg.
> > Digest::MD5::md5_hex($$, rand, time).
> >
> > Is there a recommended way to do this?
> >
> > I thought of a DBIC::PK::Auto::MD5 class, with an insert() that
> > does basically:
> >
> > my $self = shift;
> > $self->store_column(md5_hex($$, rand, time));
> > $self->next::method(@_);
> >
> > Is that an appropriate approach?
>
> http://search.cpan.org/~mikihoshi/DBIx-Class-RandomStringColumns-0.02
>/lib/DBIx/Class/RandomStringColumns.pm
Now I tried it an it fails.
I went the schema way.
This is the error message:
Can't locate object method "search" via package "My::Schema::User" at /usr/lib/perl5/vendor_perl/5.8.5/DBIx/Class/RandomStringColumns.pm line 80.
Look at
http://search.cpan.org/src/MIKIHOSHI/DBIx-Class-RandomStringColumns-0.02/lib/DBIx/Class/RandomStringColumns.pm
do { # must be unique
$val = String::Random->new->randregex(sprintf('%s{%d}', $self->rs_salt->{$column} , $self->rs_length->{$column}));
} while ($self->search({$column => $val}));
$self is a My::Schema::User object that obviously has no search method.
If I read the docs I see that search is in Class DBIx::Class::ResultSet.
Does my My::Schema::User should inherit from DBIx::Class::ResultSet?
Or is DBIx::Class::RandomStringColumns broken?
--
Bernhard Graf
More information about the Dbix-class
mailing list