I have a form that has multiple elements with the same field key; they're nested under different fieldgroups. As a result, when I try to make a MySQL view for this webform, it errors out because of duplicate column names.
One possible solution would be to make the column names be constructed from the fieldgroup name and the field name. I'm not sure how this would affect the functionality of the rest of the module, though.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 1434764-3-webform_mysql_views.module.patch | 1.77 KB | millenniumtree |
| #1 | 1434764-duplicate-fields.patch | 3.3 KB | cafuego |
Comments
Comment #1
cafuego commentedAttached patch uses a small helper to generate unique column names for the view based on a webform field key, its parent (fieldset) key if set, and the component id. Additionally, it ensures this generated name is 64 characters or less, which is a hard column name length limit in MySQL.
Please test :-)
Comment #2
cafuego commentedThe patch is present in 6.x-2.x-dev, please give that a try.
Comment #3
millenniumtreeClone a webform so that two form components in different nodes have the same cid and form_key.
The CREATE VIEW will still fail.
The compound primary key on webform_component is (nid, cid), so in the LEFT JOIN pulling in form_keys, you need a bit more specificity.
- $result = db_query("SELECT c.cid, c.form_key, p.form_key AS parent_key FROM {webform_component} AS c LEFT JOIN {webform_component} AS p ON (c.pid = p.cid) WHERE c.nid = %d AND c.type != 'fieldset' ORDER BY c.weight ASC, c.cid ASC", $nid);
+ $result = db_query("SELECT c.cid, c.form_key, p.form_key AS parent_key FROM {webform_component} AS c LEFT JOIN {webform_component} AS p ON (c.pid = p.cid AND c.nid = p.nid) WHERE c.nid = %d AND c.type != 'fieldset' ORDER BY c.weight ASC, c.cid ASC", $nid);
and probably this as well on another line
- $result = db_query('SELECT c.cid, c.name, c.form_key, p.form_key AS parent_key, p.name AS parent, c.type FROM {webform_component} c LEFT JOIN {webform_component} p ON (c.pid = p.cid) WHERE c.nid = %d AND c.type = "date" ORDER BY c.weight ASC, c.cid ASC', $nid);
+ $result = db_query('SELECT c.cid, c.name, c.form_key, p.form_key AS parent_key, p.name AS parent, c.type FROM {webform_component} c LEFT JOIN {webform_component} p ON (c.pid = p.cid AND c.nid = p.nid) WHERE c.nid = %d AND c.type = "date" ORDER BY c.weight ASC, c.cid ASC', $nid);
Patch is attached - please test. The patch may have weird line numbers, and it's really just a diff -u. I hope that's acceptable.