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.

Archive /

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

Moderators: martimiz, Sean, biapar, Willr, Ingo

Ambiguous fields in ComplexTableField


Go to End
Reply


1695 Views

Avatar
iculshaw

Community Member, 13 Posts

3 October 2008 at 1:11am

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