Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Ambiguous fields in ComplexTableField

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1428 Views
  • iculshaw
    Avatar
    Community Member
    13 Posts

    Ambiguous fields in ComplexTableField Link to this post

    Hi there,

    I have extended the ComplexTableField to administer ecommerce orders, however on joining the Member table (in the join parameter for ComplexTableField) and trying to filter the results a nice ajax error is returned.

    What i am trying to do is show the Order ID, Customer Surname, Order Status, Created Order Date and Last Updated Order Date.

    Ajax error below:

    Could not filter results: ERROR:Error 256: DATABASE ERROR: Couldn't run query: SELECT `Order`.*, `Order`.ID, if(`Order`.ClassName,`Order`.ClassName,'Order') AS RecordClassName, Surname, Status, Created FROM `Order` LEFT JOIN `Member` ON `Order`.`MemberID` = `Member`.`ID` WHERE (`Member`.`Surname` LIKE '%culs%') GROUP BY `Order`.ID | Column 'Created' in field list is ambiguous At l431

    The code i'm actually using here is (ComplexTableField Extension):

    function __construct($controller, $name, $sourceClass, $mode, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "Created DESC", $sourceJoin = "") {
          $this->mode = $mode;
          
          parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
          
          $this->Markable = true;
          $this->setPageSize(15);
          
          // search
          $search = isset($_REQUEST['TransactionSearch']) ? Convert::raw2sql($_REQUEST['TransactionSearch']) : null;
          
          if(!empty($_REQUEST['TransactionSearch'])) {
             $this->sourceFilter[] = "`Member`.`Surname` LIKE '%$search%'";
          }
          
          Requirements::javascript('ecommerce/javascript/TransactionTableField.js');
          
       }

    and the actual calling function

    $tableFields = array(
             "ID" => _t('TransactionAdmin.ORDERNO', 'Order Number'),
             "Surname" => _t('TransactionAdmin.SURNAME', 'Surname'),
             "Status" =>    _t('TransactionAdmin.STATUS', 'Status'),
             "Created" => _t('TransactionAdmin.CREATED', 'Created')
          );   
          
          // Options for drop down field
          
          $options['Unpaid'] = 'Unpaid';
          $options['Paid'] = 'Paid';
          $options['Query'] = 'Query';
          $options['Processing'] = 'Processing';
          $options['Sent'] = 'Sent';
          $options['Complete'] = 'Complete';
          $options['MemberCancelled'] = 'MemberCancelled';
          $options['AdminCancelled'] = 'AdminCancelled';
          
          $popupFields = new FieldSet(
             new DropdownField("Status", _t('TransactionAdmin.STATUS', 'Status'),$options),
             new CheckboxField("Printed", _t('TransactionAdmin.PRINTED', 'Mark as Printed'))
          );
          
          $idField = new HiddenField('ID', '', $section);
          $table = new TransactionTableField($this, "Order", "Order", $section, $tableFields, $popupFields, ((isset($filter))?array($filter):array()), null, "LEFT JOIN `Member` ON `Order`.`MemberID` = `Member`.`ID`"); //array($filter)
          $table->setParentClass(false);
          
          $fields = new FieldSet(
             new TabSet(   'Root',
                new Tab(_t('TransactionAdmin.ORDERS', 'Orders'),
                   new LiteralField("Title", $title),
                   $idField,
                   $table
                )
             )
          );

    btw i know the TransactionTableField() function caller is a bit dailywtf

    Thanks in advance

    1428 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.