[Dbix-class] Select From Dual (Again)

Richard Cox r_w_cox at btinternet.com
Fri Nov 9 16:55:30 GMT 2007


Thanks Matt that's certainly better than my stupid hack which is now in dev
null, didn't know about HashRefInflator, will take a look

Thanks for your help
Rick


--- Matt S Trout <dbix-class at trout.me.uk> wrote:

> On Fri, Nov 09, 2007 at 03:11:25PM +0000, Richard Cox wrote:
> > So all that's cool but I hit a roadblock if I want to select more than one
> > column at a time because we only have one 'dummy' column in our table class
> so
> > it gets autoviv'd
> > 
> > my @rs = $schema->resultset('Dual')->search(undef,
> >    { select => [ \'sysdate', {initcap => '\'bar\''} ],
> >      as     => [ 'dummy', 'dummy' ]
> >    },
> > );
> > 
> > for my $col (@rs) {
> >    print $col->dummy."\n"; # Bar
> > }
> > 
> > To get round this I've slung together an 'auto column' component which
> > overrides get_column
> 
> Why bother?
> 
> as => [ 'sysdate', 'initcap' ]
> 
> ...
> 
> $obj->get_column('sysdate')
> $obj->get_column('initcap')
> 
> DBIC intentionally doesn't validate the columns passed to inflate_result
> and intentionally treats _column_data as supreme if the key exists precisely
> to make this usage work without needing any extra custom code.
> 
> or you could sod off having a class at all and just use HashRefInflator so
> @rs will contain { sysdate => $systdate, initcap => $initcap } in each
> element.
> 
> Both seem simpler to me than adding+removing columns on the fly inside
> get_column ...
> 
> -- 
>       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/
> 
> _______________________________________________
> 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@lists.rawmode.org
> 




More information about the DBIx-Class mailing list