Subject: | "Has not been saved" error for certain database structure. |
The following three tables are given (MySQL, should not matter for the issue). You may
think of the reference table containing some books, which are cited in the tables a and
b:
CREATE TABLE reference (
id INTEGER PRIMARY KEY AUTO_INCREMENT
);
CREATE TABLE a (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
reference INTEGER REFERENCES reference(id)
);
CREATE TABLE b (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
a INTEGER REFERENCES a(id),
reference INTEGER REFERENCES reference(id)
);
Furthermore, for the DBIx::Class scheme of "a" we have a belongs_to relation
reference => 'Scheme::Result::Reference'
and for the scheme of "b" we have
reference => 'Scheme::Result::Reference'
as well as
a => 'Scheme::Result::Reference'.
In this situation an error occurs when trying to enter information into the table "b".
My guess is, that the AJAX template does not use form names that are concise
enough in this situation. Two combo boxes with the same name "reference" are
created, one in the main form and one in the tab "Create new a". As a result the
Controller seems to think that "reference" takes an array of values.
Changing the belongs_to relation in 'Scheme::Result::B' to
'reference_' => 'Scheme::Result::Reference', 'reference'
seems to fix the issue as a workaround.
For the sake of completeness:
My perl version is 5.10.1. I am using Debian Squeeze, installed Catalyst, all modules
and extra-modules via APT and Catalyst::Plugin::AutoCRUD via CPAN.
uname -svrmo returns
Linux 2.6.32-5-amd64 #1 SMP Fri Dec 10 15:35:08 UTC 2010 x86_64 GNU/Linux
I am using the current stable version, i.e. 0.68 of Catalyst::Plugin::AutoCRUD.