[Dbix-class] DBIX::Class - CGI::FormBuilder select-options problem

Jess Robinson castaway at desert-island.demon.co.uk
Tue Dec 12 13:35:51 GMT 2006



On Tue, 12 Dec 2006, Igor Longagnani wrote:

> Hi,
> i am a newbie with DBIx::Class and Catalyst so i beg your pardon in
> advance for my question:
>
> I do use with success DBIx::Class in other situations (easy ones) and
> I am trying to populate the option fields of a "select tag" named
> "soggetto" described through CGI::Formbuilder
> with data selected from an Oracle DB via DBIx::Class/Catalyst webapp
> runinng on catalyst developement server on port 3000.
> This is what doesn't work, i mean syntax is correct but output not what
> i excpected:
>
> Inside a Catalyst Controller class:
>
> my @data = $c->model('myDB::AnaEsercenti')->search(undef,{select =>
> [qw/userid name/]})->all();
> $c->form->options({ soggetto  => \@data});
>
> I get the following (from HTML source page) build through a Template
> Toolkit tag [%  form.fieldrefs.soggetto.tag %]
>
> <select class="fb_select" id="soggetto" name="soggetto">
>  <option value="">-select-</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4215d64)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4216544)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4216760)</option>
>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421697c)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4216b98)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421b440)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421b65c)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421b878)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421ba94)</option>
>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421bcb0)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421becc)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421c0e8)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421c304)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421f934)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421fb50)</option>
>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421fd6c)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x421ff88)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x42201a4)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x42203c0)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x42205dc)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4223a5c)</option>
>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4223c78)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4223e94)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x42240b0)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x42242cc)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x42244e8)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4224704)</option>
>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4224920)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4227f48)</option>
>  <option>myApp::Model::myDB::AnaEsercenti=HASH(0x4228164)</option>
>  </select>
>
>
> I know data is present because i enabled the debugger and through
> $c->log->debug and Data::Dumper
> i was able to find these kind of data structure for every record
>
>  bless( { "result_source" =>
> $c->form->{"options"}{"soggetto"}[0]{"result_source"},
>                "_in_storage" => 1,
>                "_column_data" => {
>                                                 "cognome" => undef,
>                                                 "userid" => 99700001
>                                                    }
>  }, 'myApp::Model::myDB::AnaUtenti' ),
>
>
> but i couldnt find a proper, already existing method to extract that
> "_column_data " data :)
>
> I know am doing somethig wrong and i am doing my own micro-sub to
> extract them
> but  i am sure i am missing something important.
>
> Environment in WinXP is fully functional ( i don't get installation
> errors nor excution ones except when i make syntax errors myself)
> and  is mainly composed by:
> - Catalyst 5.7006
> - DBIx::Class
> - Template Toolkit
> - CGI::FormBuilder
> in their latest versions.
>
> Thanks in advance for your precious efforts.
>


Hi Igor,

That looks more like a Catalyst/FormBuilder question.. You're passing it a 
list of DBIx::Class objects, and it doesnt know what to do with them.

Try doing this instead:

  my @data = $c->model('myDB::AnaEsercenti')->search(undef,{select 
=> [qw/userid name/]})->all();
$c->form->options({ soggretto => [ map { [ $_->get_column('userid'),
                                            $_->get_column('name') ]
                                        } @data ] });

Jess




More information about the Dbix-class mailing list