Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Can't extend UserDefinedForm (Unknown column 'UserDefinedForm.Version' in 'field list')


Reply


6 Posts   839 Views

Avatar
Marcinkonys

Community Member, 11 Posts

21 January 2013 at 11:30am

Edited: 21/01/2013 12:22pm

Hey guys,

I thought this would be a very easy thing to accomplish, but have been struggling with this for hours now. Basically what I want to do is have a page type that lets you create a form (have all the functionality of UserDefinedForm), PLUS a file upload field to upload a PDF.

Isn't that just extending UserDefinedForm like this?:

<?php

class DokumentoPuslapis extends UserDefinedForm {

   public static $has_one = array(
      'Taisykles' => 'File'
   );

   public function getCMSFields() {
      $fields = parent::getCMSFields();
      $fields->addFieldToTab('Root.PDF', new UploadField('Taisykles'));
      return $fields;
   }

}
class DokumentoPuslapis_Controller extends UserDefinedForm_Controller {
   public function init() {
      parent::init();
   }
}

Trying to access a newly created page of this type for editing gives me this:

[User Error] Couldn't run query: SELECT DISTINCT "SiteTree"."ClassName", "SiteTree"."Created", "SiteTree"."LastEdited", "DokumentoPuslapis"."TaisyklesID", CASE WHEN "SiteTree"."ClassName" IN ('SiteTree', 'Page', 'DokumentuKatalogas', 'KontaktuPuslapis', 'NaujienosPuslapis', 'NaujienuKatalogas', 'PagrindinisPuslapis', 'PereinantisPuslapis', 'ErrorPage', 'RedirectorPage', 'VirtualPage', 'UserDefinedForm', 'DokumentoPuslapis', 'DokumentuPuslapis') THEN "SiteTree"."Version" WHEN "SiteTree"."ClassName" IN ('UserDefinedForm', 'DokumentoPuslapis', 'DokumentuPuslapis') THEN "UserDefinedForm"."Version" ELSE NULL END AS "Version", "SiteTree"."ID", CASE WHEN "SiteTree"."ClassName" IS NOT NULL THEN "SiteTree"."ClassName" ELSE 'SiteTree' END AS "RecordClassName", "SiteTree"."Sort" FROM "SiteTree" LEFT JOIN "DokumentoPuslapis" ON "DokumentoPuslapis"."ID" = "SiteTree"."ID" WHERE ("DokumentoPuslapis"."ID" = 41) AND ("SiteTree"."ClassName" IN ('DokumentoPuslapis')) ORDER BY "SiteTree"."Sort" ASC LIMIT 1 Unknown column 'UserDefinedForm.Version' in 'field list'
GET /ss3/admin/pages/edit/show/41

Line 580 in C:\wamp\www\ss3\framework\model\MySQLDatabase.php

Might this have to do with me recently installing the Translatable module? Or is my code simply wrong?

EDIT: After some fiddling I came up with a partial solution.

<?php

class UDFDecorator extends DataExtension {
   
   static $has_one = array(
      'Taisykles' => 'File'
   );
   
   public function getCMSFields() {
      $this->extend('updateCMSFields', $fields);
      return $fields;
   }
   
   public function updateCMSFields(FieldList $fields) {
      $fields->push(new UploadField('Taisykles', 'Prisegamas failas'));
   }
}

_config.php:

Object::add_extension('UserDefinedForm', 'UDFDecorator');

Still, that makes ALL the forms have this functionality. Shouldn't extending the UDF class work?

Avatar
FungshuiElephant

Community Member, 57 Posts

21 January 2013 at 11:48pm

I have this same problem too.
Reading through the SQL it seems that the version column can't be found because the UserDefinedForm table isn't included in the list of tables to query.
I too added a field to my extended class, if I remove the extra field I don't get the error. I think the problem may be due to the code that builds the table list and I wonder whether a combination of your two approaches would work; i.e. extend UserDefinedForm and then decorate the extended class to add the additional fields you require.

Avatar
Marcinkonys

Community Member, 11 Posts

22 January 2013 at 4:49am

Edited: 22/01/2013 5:00am

Thanks for the reply, FungshuiElephant!

I tried your suggestion. Unfortunately, that still produces the same error here :/

... the UserDefinedForm table isn't included in the list of tables to query.


Regarding UserDefinedForm: did you check the database to see whether such a table exists? Because my DB didn't even have one with such a name.

Avatar
FungshuiElephant

Community Member, 57 Posts

22 January 2013 at 5:48am

I definitely have a UserDefinedForm table, along with UserDefinedForm_versions and UserDefinedForm_Live.

I think the problem here is caused by the versioning; both SiteTree and UserDefinedForm are versioned objects. I looked through the code and this seems to be catered for, i.e. you can have an object that's versioned twice; in fact that's where the case statement in the SQL code comes from.

The code that generates the SQL statement thinks that it's only looking for fields on SiteTree and your new extended class, it's not interested in the fields on UserDefinedForm so it doesn't include that table in the SQL and the bit of code that augments the query to do the versioning stuff is after the code to choose the tables. (See getFinalisedQuery in DataQuery in SSv3.0.3).

I think that's a bug.

I've submitted a [url=http://open.silverstripe.org/ticket/8210]ticket [/url] with a patch to fix this and another [url=http://open.silverstripe.org/ticket/8208]bug[/url] which got in the way of debugging this.

Avatar
Marcinkonys

Community Member, 11 Posts

22 January 2013 at 5:53am

Sweet! Hoping they'll fix this soon.

Avatar
neilcreagh

Community Member, 97 Posts

20 March 2013 at 5:48am

Edited: 20/03/2013 6:12am

Update: I just downloaded the very latest version of Userforms from Github and replaced, then ran dev/build and this is working for me now.