[Dbix-class] Select From Dual (Again)
Matt S Trout
dbix-class at trout.me.uk
Fri Nov 9 16:01:23 GMT 2007
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/
More information about the DBIx-Class
mailing list