Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Can't extend UserDefinedForm (Unknown column 'UserDefinedForm.Version' in 'field list')

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 731 Views
  • Marcinkonys
    Avatar
    Community Member
    11 Posts

    Can't extend UserDefinedForm (Unknown column 'UserDefinedForm.Version' in 'field list') Link to this post

    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?

  • FungshuiElephant
    Avatar
    Community Member
    57 Posts

    Re: Can't extend UserDefinedForm (Unknown column 'UserDefinedForm.Version' in 'field list') Link to this post

    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.

  • Marcinkonys
    Avatar
    Community Member
    11 Posts

    Re: Can't extend UserDefinedForm (Unknown column 'UserDefinedForm.Version' in 'field list') Link to this post

    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.

  • FungshuiElephant
    Avatar
    Community Member
    57 Posts

    Re: Can't extend UserDefinedForm (Unknown column 'UserDefinedForm.Version' in 'field list') Link to this post

    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 ticket with a patch to fix this and another bug which got in the way of debugging this.

  • Marcinkonys
    Avatar
    Community Member
    11 Posts

    Re: Can't extend UserDefinedForm (Unknown column 'UserDefinedForm.Version' in 'field list') Link to this post

    Sweet! Hoping they'll fix this soon.

  • neilcreagh
    Avatar
    Community Member
    90 Posts

    Re: Can't extend UserDefinedForm (Unknown column 'UserDefinedForm.Version' in 'field list') Link to this post

    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.

    731 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.