[html-formfu] Model::DBIC and belongs_to problem

Alex Povolotsky tarkhil at over.ru
Sat Jan 9 16:31:41 GMT 2010


Hello!

I have two tables, for a bare mininmum,

create table jail(jid serial primary key, name varchar not null);
create table hosting_domain(domid serial primary key, name varchar not 
null, jailid int not null references jail(jid));

DBIx::Class::Schema::Loader gives me

__PACKAGE__->belongs_to("jailid", "Hosting::Schema::Result::Jail", { jid 
=> "jailid" });

for HostingDomain.pm and

__PACKAGE__->has_many(
   "hosting_domains",
   "Hosting::Schema::Result::HostingDomain",
   { "foreign.jailid" => "self.jid" },
);

for Jail.pm

which seems quite logical.

However, when I try to make a form for domain creation with jail selection

---
model_config:
   resultset: HostingDomain

elements:
   - type: Text
     name: name
     label: Domain name
     constraints:
       - Required

   - type: Select
     nested: jailid
     model_config:
       resultset: Jail

   - type: Submit
     label: Submit

I'm getting an error

Caught exception in Hosting::Controller::Domain->add "cannot set nested 
at /usr/local/lib/perl5/site_perl/5.10.1/HTML/FormFu/ObjectUtil.pm line 362
  at 
/usr/local/lib/perl5/site_perl/5.10.1/Catalyst/Controller/HTML/FormFu/Action/FormConfig.pm 
line 42
  at 
/usr/local/lib/perl5/site_perl/5.10.1/Catalyst/Controller/HTML/FormFu/Action/FormConfig.pm 
line 42"

Reading manual and examples, I've found nothing usable in my case.

How do I make a proper Select control, to display jail name and select 
jail id? Second question, how do I add '- Select -' entry to control, 
without any value, to be shown in first place?

Alex.




More information about the HTML-FormFu mailing list