[Catalyst] edit has_many relation with FormFu

Robyn Jonahs learn.catalyst at gmail.com
Wed Apr 11 14:53:49 GMT 2012


Hi did you ever get this resolved? I am trying to get a many_to_many
relationship in FormFu to work in Catalyst also with a join table. I am
having trouble figuring out the proper YAML to put into the form. I was
hoping that you figured out the problem in the end and could share the
solution.



On Mon, Oct 27, 2008 at 6:27 AM, David Schmidt <davewood at gmx.at> wrote:

> Another mail I got from outside of the Mailinglist strengthened my
> theory (composed primary keys are bad for nested_name/Repeatable
> Types)
>
> Upon adding a atomic primary key to the picture_projects table I now
> receive the following error when trying to edit a project
>
> > CREATE TABLE picture_projects (
> >         id              INTEGER PRIMARY KEY,
> >         picture_id      INTEGER,
> >         project_id      INTEGER,
> >         position        INTEGER,
> >         UNIQUE (project_id, picture_id),
> >         FOREIGN KEY (project_id) references projects(id),
> >         FOREIGN KEY (picture_id) references pictures(id)
> > );
>
> http://131.130.239.28:3000/projects/formfu_edit/1
>
> DBI Exception: DBD::SQLite::db prepare_cached failed: ambiguous column
> name: id(1) at dbdimp.c line 271 [for Statement "SELECT id FROM
> picture_projects me  JOIN pictures picture ON ( picture.id =3D
> me.picture_id ) WHERE ( me.id =3D ? )"] at
> /usr/local/share/perl/5.8.8/DBIx/Class/Schema.pm line 954
>
> I could simply avoid this error by not naming the primary key in table
> picture_projects "id" (ambiguous with primary key "id" in table
> projects) but I sense either a bug in Catalyst/FormFu interaction or
> rather likely some misconfiguration on my behalf.
>
> Is there a way to make catalyst call:
>
> "SELECT me.id FROM picture_projects me  JOIN pictures picture ON (
> picture.id =3D me.picture_id ) WHERE ( me.id =3D ? )"
> rather then
> "SELECT id FROM picture_projects me  JOIN pictures picture ON (
> picture.id =3D me.picture_id ) WHERE ( me.id =3D ? )"
>
> ?
>
> david
>
> On Mon, Oct 27, 2008 at 10:23 AM, David Schmidt <davewood at gmx.at> wrote:
> > Hello and thanks for your reply.
> > I tried adding model_config before but it didn't change anything.
> > Here is a full formfu_create.yml listing:
> >
> >> indicator: submit
> >> elements:
> >> - type: Text
> >>   name: title
> >>   label: Title
> >>
> >> - type: Textarea
> >>   name: description
> >>   label: Description
> >>
> >> - type: Select
> >>   name: pictures
> >>   label: Pictures
> >>   multiple: 1
> >>   size: 10
> >>
> >> - type: Select
> >>   name: active
> >>   label: Status
> >>   options:
> >>     - [ '0', 'inactive' ]
> >>     - [ '1', 'active' ]
> >>
> >> - type: Repeatable
> >>   nested_name: picture_projects
> >>   model_config:
> >>     model: 'myDB::PictureProjects'
> >>   elements:
> >>     - type: Hidden
> >>       name: project_id
> >>     - type: Hidden
> >>       name: picture_id
> >>     - type: Text
> >>       label: Position
> >>       name: position
> >>
> >> - type: Submit
> >>   name: submit
> >>   value: Submit
> >>
> >> constraints:
> >> - Required
> >
> > The only thing different with your example I can see is that you
> > apparently have a primary key consisting of one column while I have a
> > composed primary key of the two foreign keys of the m:n relation.
> >
> > friendly greetings
> > david
> >
> > On Sun, Oct 26, 2008 at 10:59 PM, Chris <hutchinson.chris at gmail.com>
> wrote:
> >> Hi David,
> >>
> >>> I want to edit a m:n relation between projects and pictures (a project
> >>> may have many pictures). It is displayed correctly but upon submit the
> >>> following error message occurs:
> >>> NOTE: 7 is the project ID which seems to be interpreted as a column
> name
> >>>
> >>> DBI Exception: DBD::SQLite::db prepare_cached failed: near ".7":
> >>> syntax error(1) at dbdimp.c line 271 [for Statement "SELECT
> >>> me.picture_id, me.project_id, me.position FROM picture_projects me
> >>> WHERE ( ( ( me.7 IS NULL ) AND ( me.project_id =3D ? ) ) )"] at
> >>> /usr/local/share/perl/5.8.8/DBIx/Class/Schema.pm line 954
> >>>
> >>> in this line in Controller/Projects.pm:
> >>>>if ($form->submitted_and_valid) {
> >>>>        $form->model->update($project);
> >>>
> >>>
> >>> Any help is highly appreciated as I am stuck with this problem since a
> >>> few days already.
> >>>
> >>> in lib/MyApp/Schema/Projects.pm:
> >>>> __PACKAGE__->has_many(picture_projects =3D>
> 'Oberhumer::Schema::PictureProjects', 'project_id');
> >>>> __PACKAGE__->many_to_many(pictures =3D> 'picture_projects', 'picture=
');
> >>>
> >>> in myapp02.sql:
> >>>>CREATE TABLE pictures (
> >>>>        id       INTEGER PRIMARY KEY,
> >>>>        title    TEXT,
> >>>>        info     TEXT,
> >>>>        filename TEXT,
> >>>>        created  datetime
> >>>>);
> >>>>
> >>>>CREATE TABLE picture_projects (
> >>>>        picture_id      INTEGER,
> >>>>        project_id      INTEGER,
> >>>>        position        INTEGER,
> >>>>        PRIMARY KEY (project_id, picture_id)
> >>>>);
> >>>
> >>> in root/forms/projects/formfu_create.yml:
> >>>>- type: Repeatable
> >>>>  nested_name: picture_projects
> >>>>  elements:
> >>>>    - type: Hidden
> >>>>      name: project_id
> >>>>    - type: Hidden
> >>>>      name: picture_id
> >>>>    - type: Text
> >>>>      label: Position
> >>>>      name: position
> >>>
> >>> with friendly greetings
> >>> David Schmidt
> >>>
> >>
> >> What does the rest of formfu_create.yml contain?
> >>
> >> I've seen the same problem. I vaguely recall needing a model_config
> >> section in the formfu config, something like this (as a perl hash):
> >>
> >> {       type =3D> 'Fieldset', legend=3D>'Plant Zones', elements =3D> [
> >>                                {
> >>                                        type            =3D> 'Repeatabl=
e',
> >>                                        nested_name     =3D>
>  'plant_zones',
> >>
> >>                                        model_config    =3D>      {
> >>                                                model
>         =3D>      'DB::PlantZones',
> >>                                                new_empty_row_multi
> =3D>      'zone_id',
> >>                                        },
> >>
> >>                                        attributes      =3D>      {
> >>                                                class           =3D>
>  'zone-block',
> >>                                        },
> >>
> >>                                        elements        =3D>      [
> >>                                                {
> >>                                                        type    =3D>
>  'Hidden',
> >>                                                        name    =3D>
>  'id',
> >>                                                },
> >>
> >> ... etc...
> >>
> >> - Chris
> >>
> >> _______________________________________________
> >> List: Catalyst at lists.scsys.co.uk
> >> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> >> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> >> Dev site: http://dev.catalyst.perl.org/
> >>
> >
> >
> >
> > --
> > David Schmidt   |   http://www.fm5.at
> >
>
>
>
> --
> David Schmidt   |   http://www.fm5.at
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120411/6bd5b=
551/attachment.htm


More information about the Catalyst mailing list