<b>Short version</b>: If you have a HTML::FormHandler search form without a "has_field '+item_class'" (there's no data-base row corresponding to its contents) how to you reach your DBIx::Class schemas to populate a drop-down menu?<div>
<br></div><div><br></div><div><b>Long version</b>: This is in the context of a Catalyst app -- however, I do know this is either FormHandler question or a DBIC question, and not intrinsically a Catalyst question, but... hoping the wise folks here can nudge me in the right direction...</div>
<div><br></div><div>We have several DBIC resultsets including Incident and Country. The Incident record has this relationship:</div><div><font class="Apple-style-span" color="#339999">__PACKAGE__->belongs_to( 'country' => 'Incident::Schema::DB::Result::Country' );</font></div>
<div><br></div><div>(And the country schema <font class="Apple-style-span" color="#339999">has_many</font> incidents, of course)</div><div><br></div><div>For the CRUD form related to the actual incident table, we have a matching HTML::FormHandler package with its</div>
<div><font class="Apple-style-span" color="#339999">has '+item_class'</font></div><div>as expected. This makes it easy to create a </div><div><font class="Apple-style-span" color="#339999">sub options_country {</font></div>
<div><font class="Apple-style-span" color="#339999"> my $self = shift;</font></div><div><font class="Apple-style-span" color="#339999"> return unless $self->schema;</font></div><div><span class="Apple-style-span" style="color: rgb(51, 153, 153); "> my $rs = $self->schema->resultset('Country');</span></div>
<div><span class="Apple-style-span" style="color: rgb(51, 153, 153); "> #...</span></div><div><font class="Apple-style-span" color="#339999">}</font></div><div>subroutine for the form, for populating a country drop-down menu in the HTML.</div>
<div><br></div><div>But!</div><div><br></div><div>For the SEARCH form, we are not interested in CRUD, plus we have extra fields (for example, we want the user to be able to bracket dates with a start-field and an end-field) so there's no one-to-one correlation with the database table -- meaning there's no "item_class" for the search form. And hence no schema to rely on.</div>
<div><br></div><div>What we're looking for now -- unless there's a better more obvious paradigm -- is a way to get from an instance of the schema-object, back to the resultset, for searching.</div><meta charset="utf-8"><div>
<font class="Apple-style-span" color="#339999">sub options_country {</font></div><div><font class="Apple-style-span" color="#339999"> my $self = shift; # note $c is not available here :(</font></div><div><font class="Apple-style-span" color="#339999"> # $self->schema will be UNDEF here</font></div>
<div><font class="Apple-style-span" color="#339999"> my $obj = Spill::Schema::DB::Result::Country->new; # Hard-wired, yes, is there a better way?</font></div><div><font class="Apple-style-span" color="#339999"> my $rs = $obj->???</font></div>
<div><font class="Apple-style-span" color="#339999"> # ?</font></div><div><font class="Apple-style-span" color="#339999">}</font></div><div><br></div><div>I've looked at </div><div>- $obj->result_source (Can't call method "resolve" on an undefined valued in DBIx/Class/Row) </div>
<div>- $obj->result_source_instance->resultset (Can't call method "default_resultset_attributes" on an undef value in DBIx/Class/ResultSource)</div><div>- $obj->result_source_instance->resultset_class->search({},{}) (Can't use string as a HASH ref in DBIx/Class/ResultSet)</div>
<div>and a couple other dead ends.</div><div><br></div><div>It's likely to be something obvious I've overlooked. :( Suggestions?</div><div><br>-- <br>The first step towards getting somewhere is to decide that you are not going to stay where you are. -- J.P.Morgan<br>
</div>