Subject: | Ambiguous columnname for many-to-many relationships using default_values() |
our db-schema is not the same as the test-db, we use only _id names for
all id-columns in every table, also in the many-to-many-linking-table.
Schema:
CREATE TABLE users (
user_id INTEGER PRIMARY KEY NOT NULL,
name TEXT NOT NULL
);
CREATE TABLE bands (
band_id INTEGER PRIMARY KEY NOT NULL,
band TEXT NOT NULL
);
CREATE TABLE user2bands (
user_id INTEGER NOT NULL,
band_id INTEGER NOT NULL,
PRIMARY KEY (user_id, band_id)
);
So when we call $form->model->default_values($user) we get following error:
ERROR 1052 (23000): Column 'band_id' in field list is ambiguous
The executes query is:
SELECT band_id FROM user2bands me JOIN bands band ON ( band.band_id =
me.band_id ) WHERE ( me.user_id = 31 );
It should be SELECT me.band_id FROM ...
when we change the row ~202 in HTML/FormFu/Model/DBIC.pm
from:
my @defaults = $dbic->$name->get_column($col)->all;
to:
my @defaults = $dbic->$name->get_column("me.$col")->all;
it works currently, but i am not sure if this is the right way.