Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

FormFu many_to_many YAML declaration

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


learn.catalyst at gmail

Apr 11, 2012, 10:09 AM

Post #1 of 2 (211 views)
Permalink
FormFu many_to_many YAML declaration

Hi,

I am having trouble with understanding how to get Many to Many
relationships into a FormFu form via YAML.

Consider the tutorial example...
https://metacpan.org/module/Catalyst::Manual::Tutorial::09_AdvancedCRUD::09_FormFu

The authors are placed into a select element.

<snip>
} else {
# Get the authors from the DB
my @author_objs = $c->model("DB::Author")->all();
# Create an array of arrayrefs where each arrayref is an author
my @authors;
foreach (sort {$a->last_name cmp $b->last_name} @author_objs) {
push(@authors, [$_->id, $_->last_name]);
}
# Get the select added by the config file
my $select = $form->get_element({type => 'Select'});
# Add the authors to it
$select->options(\@authors);
}
</snip>

and then in the form set up config

<snip>
- type: Select
name: authors
label: Author
</snip>



What if I don't want the authors in a select field but a text field? Can I
do that?


I have been trying to use something like in
http://search.cpan.org/~pshangov/HTML-FormFu-Model-DBIC-0.09002/lib/HTML/FormFu/Model/DBIC.pm#has_many_and_many_to_many_relationships

but that example schema set does not have the "many-to-many join table
between books & authors" as in the tutorial.
https://metacpan.org/module/Catalyst::Manual::Tutorial::03_MoreCatalystBasics#CREATE-A-SQLITE-DATABASE

I can't figure out how to write the YAML to get FormFu to put the data into
my edit form while using the many to many join table. Can anyone help out?

Thanks in advance.


brainbuz at brainbuz

Apr 12, 2012, 8:35 AM

Post #2 of 2 (193 views)
Permalink
Re: FormFu many_to_many YAML declaration [In reply to]

> Hi,
>
> I am having trouble with understanding how to get Many to Many
> relationships into a FormFu form via YAML.
>
> Consider the tutorial example...
> https://metacpan.org/module/Catalyst::Manual::Tutorial::09_AdvancedCRUD::09_FormFu
>
> The authors are placed into a select element.
>
> <snip>
> } else {
> # Get the authors from the DB
> my @author_objs = $c->model("DB::Author")->all();
> # Create an array of arrayrefs where each arrayref is an author
> my @authors;
> foreach (sort {$a->last_name cmp $b->last_name} @author_objs) {
> push(@authors, [$_->id, $_->last_name]);
> }
> # Get the select added by the config file
> my $select = $form->get_element({type => 'Select'});
> # Add the authors to it
> $select->options(\@authors);
> }
> </snip>
>
> and then in the form set up config
>
> <snip>
> - type: Select
> name: authors
> label: Author
> </snip>
>
>
>
> What if I don't want the authors in a select field but a text field? Can I
> do that?
>
>
> I have been trying to use something like in
> http://search.cpan.org/~pshangov/HTML-FormFu-Model-DBIC-0.09002/lib/HTML/FormFu/Model/DBIC.pm#has_many_and_many_to_many_relationships
>
> but that example schema set does not have the "many-to-many join table
> between books & authors" as in the tutorial.
> https://metacpan.org/module/Catalyst::Manual::Tutorial::03_MoreCatalystBasics#CREATE-A-SQLITE-DATABASE
>
> I can't figure out how to write the YAML to get FormFu to put the data
> into
> my edit form while using the many to many join table. Can anyone help out?
>
> Thanks in advance.
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>



_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.