Hi @Johnny,
Working with setRelation this doc page shows the availability of a fourth parameter for a WHERE clause.
$crud->setRelation('officeCode', 'offices', 'city', ['is_deleted' => 'no'])
However two issues I have encountered:
- using the [ and ] does not work - it throws a ParseError: syntax error, unexpected token “=”, expecting “]”
For example when using this code:
$crud->setRelation('ParentCompanyID','company','{Name} (ID:{CompanyID} IsParent:{IsParent})',[IsParent = '1']);
While this code with double quotes (since single quotes inside) instead of [ ] does work as desired:
$crud->setRelation('ParentCompanyID','company','{Name} (ID:{CompanyID} IsParent:{IsParent})',"IsParent = '1'");
And for what it is worth, I don’t think the => is a valid MySQL conditional operator.
- I cannot use an OR in the WHERE without adding parentheses…
$crud->setRelation('ParentCompanyID','company','{Name} (ID:{CompanyID} IsParent:{IsParent})',"IsParent = '1' OR ParentID IS NULL");
Results in " Something went wrong! Either the user doesn’t have access to this row, either the row doesn’t exist."
While this appears to work fine
$crud->setRelation('ParentCompanyID','company','{Name} (ID:{CompanyID} IsParent:{IsParent})',"(IsParent = '1' OR ParentID IS NULL)");
This is a more minor issue but worth noting.
What is the difference between setRelation and setRelationDynamic? Does setRelation only do the lookup the first time the CRUD is loaded while the dynamic version does it on every record? Or something like this? Any advice when to use one versus the other?
Lastly, I would add my “vote” to have the ability to set ORDER again in v3. I do note in this forum item you said it causes a performance hit. How much of a hit?
Thanks,
Ira