adding an additional QQ::Clause to a datagrid causes an error
Sun, 07/11/2010 - 14:57
Hi,
I was trying to add an QQ::Clause(QQ::Expand(...)) to a datagrid that uses a paginator and always got an error.
I think line 17 in file in includes/qcubed/_core/codegen/templates/db_orm/meta_datagrid/meta_data_binder.tpl
$objClauses = $this->clsAdditionalClauses;should read
array_push($objClauses, $this->clsAdditionalClauses);can someone please confirm this? if yes, I'll open a ticket and (try to) provide the patch myself (I still have two other pending... :) )

Can you post the code snippet that causes this crash? Also, which version of qcubed are you seeing this in?
this code:
$this->dtgClients = new ClientsDataGrid($this);$this->dtgClients->AdditionalClauses =
QQ::Expand(QQN::Clients()->Country);
results in this error:
array_push(): First argument should be an arrayusing
$this->dtgClients->AdditionalClauses =QQ::Clause(QQ::Expand(QQN::Clients()->Country));
or
$this->dtgClients->AdditionalClauses =array(QQ::Expand(QQN::Clients()->Country));
causes this error
Unable to cast Array to QQClauseEdit: qcubed version 1.1.1
That doesn't make much sense.
$this->dtgClients->AdditionalClauses = array(QQ::Expand(QQN::Clients()->Country));This looks like the intended approach, and is basically overwriting the earlier code of:
$objClauses = array();Having one more item in the array shouldn't cause any difference in the interpretation of the clauses. ie: If AdditionalClauses breaks, so should Limits caused by paging.
Where is the cast error being thrown from?
calling code
$this->dtgVetRacas = new VetRacasDataGrid($this,'dtgVetRacas');$this->dtgVetRacas->AdditionalClauses = QQ::Expand(QQN::VetRacas()->Especie);
error in line 259
Line 254: if ($objClause = $this->OrderByClause)Line 255: array_push($objClauses, $objClause);
Line 256:
Line 257: // Add the LimitClause information, as well
Line 258: if ($objClause = $this->LimitClause)
Line 259: array_push($objClauses, $objClause);
Line 260:
Line 261: // Set the DataSource to be a Query result from VetRacas, given the clauses above
Line 262: $this->DataSource = VetRacas::QueryArray($objConditions, $objClauses);
Line 263: }
Line 264:
call stack
#0 (): QcodoHandleError()#1 /includes/meta_controls/generated/VetRacasDataGridGen.class.php(259): array_push()
#2 /includes/qcubed/_core/base_controls/QFormBase.class.php(342): VetRacasDataGridGen->MetaDataBinder()
#3 /includes/qcubed/_core/base_controls/QPaginatedControl.class.php(76): QFormBase->CallDataBinder()
#4 /includes/qcubed/_core/base_controls/QDataGridBase.class.php(697): QPaginatedControl->DataBind()
#5 /includes/qcubed/_core/base_controls/QControlBase.class.php(1068): QDataGridBase->GetControlHtml()
#6 /modules/myform.tpl.php(24): QControlBase->Render()
#7 /includes/qcubed/_core/base_controls/QFormBase.class.php(868): require()
#8 /includes/qcubed/_core/base_controls/QFormBase.class.php(316): QFormBase->Render()
#9 /modules/myform.php(136): QFormBase::Run()
That one I expect to crash. I suppose we could auto-detect that it's not an array, and try wrapping it, but that still won't work if wrapping it in an array crashes already.
Can you test with this instead, and show me the crash report?
$this->dtgClients->AdditionalClauses = array(QQ::Expand(QQN::Clients()->Country));I just hit this same issue.
AdditionalClauses on the generated meta datagrids requires a QQ::Clause - because of
case 'AdditionalClauses':try {
return ($this->clsAdditionalClauses = QType::Cast($mixValue, 'QQClause'));
} catch (QCallerException $objExc) {
$objExc->IncrementOffset();
throw $objExc;
}
, so doing
$this->dtgClients->AdditionalClauses = array(QQ::Expand(QQN::Clients()->Country));causes an "Unable to cast Array to QQClause". So I think this is a real bug.
Ahh, yep, that's definitely a conflict. It should be casting to array.