[Dbix-class] tinyint and enum mapping
Matt S Trout
dbix-class at trout.me.uk
Tue Oct 28 00:05:48 GMT 2008
On Fri, Oct 24, 2008 at 05:34:06PM +0400, jackal wrote:
> On Friday 24 October 2008 17:11:46 Fayland Lam wrote:
> > hi, folks.
> >
> > basically I prefers tinyint better than enum becaue I don't need alter
> > table when adding another value to col.
> >
> > see now we have a column 'status' and it's tinyint instead of enum
> > then I want my code treats it as enum instead of tinyint. it means I
> > can do something like follows:
> >
> > ->create( { status => 'banned' } );
> > ->update( { status => 'warned' } );
> > and ->delete and others.
> >
> > I think InflateColumn is what I want. but I just wonder if there is a
> > plugin for that? so that I can just add it into load_components and
> > set an attribute when add_columns.
> > is there a component around? or should I write one? :)
> >
> > Thanks.
>
> No, InflateColumn works with objects only. It cannot *modify* data.
> It's destination - to deflate object into scalar for DB, and inflate scalar
> into object. Not to modify.
>
> Module I want to contribute, ModifyColumn, can do it:
>
> my @status = qw/ok banned warned something else/;
> __PACKAGE__->modify_column('status', {
> inflate => sub { $status[$_[0]] },
> deflate => sub {
> my $value = shift;
> for (my $i=0; $i<=$#status; $i++) {
> return $i if $status[$i] eq $value;
> }
> return undef;
> }
> });
>
> http://lists.scsys.co.uk/pipermail/dbix-class/2008-October/006968.html
Be nice if you could handle >1 value and >1 actual column - the biggest
annoyance of inflate_column has been the limitation of 1 column and 1
attribute.
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/
More information about the DBIx-Class
mailing list