[Catalyst] edit has_many relation with FormFu
David Schmidt
davewood at gmx.at
Mon Oct 27 10:27:49 GMT 2008
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 =
me.picture_id ) WHERE ( me.id = ? )"] 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 = me.picture_id ) WHERE ( me.id = ? )"
rather then
"SELECT id FROM picture_projects me JOIN pictures picture ON (
picture.id = me.picture_id ) WHERE ( me.id = ? )"
?
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 = ? ) ) )"] 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 => 'Oberhumer::Schema::PictureProjects', 'project_id');
>>>> __PACKAGE__->many_to_many(pictures => '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 => 'Fieldset', legend=>'Plant Zones', elements => [
>> {
>> type => 'Repeatable',
>> nested_name => 'plant_zones',
>>
>> model_config => {
>> model => 'DB::PlantZones',
>> new_empty_row_multi => 'zone_id',
>> },
>>
>> attributes => {
>> class => 'zone-block',
>> },
>>
>> elements => [
>> {
>> type => 'Hidden',
>> name => '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
More information about the Catalyst
mailing list