So It appears I will need to join the tables rather then modify the row. I have the following which doesn't product any additional output. (looking at the json in firebug)
public function prepareQueryBeforeCount(xPDOQuery $c) {
$c->innerJoin('modUserProfile','Profile', 'IYKT.user_id = Profile.internalKey');
//search query
$query = $this->getProperty('query');
if (!empty($query)) {
$c->where(array(
'trans_id:LIKE' => '%'.$query.'%',
'OR:Profile.fullname:LIKE' => '%'.$query.'%',
));
}
return $c;
}
My schema is as follows
<object class="IYKT" table="iykt" extends="xPDOSimpleObject">
<field key="user_id" dbtype="int" phptype="integer" null="false" default=""/>
<field key="trans_id" dbtype="varchar" phptype="string" precision="255" null="false" default=""/>
<field key="createdon" dbtype="datetime" phptype="datetime" null="true"/>
<field key="createdby" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
<aggregate alias="Profile" class="modUserProfile" local="user_id" foreign="internalKey" cardinality="one" owner="foreign"/>
</object>
EDIT
On further investigation it appears that my join is not working properly. the SQL produced via a snippet when a join is used is
string(596) "SELECT `IYKT`.`id` AS `IYKT_id`, `IYKT`.`user_id` AS `IYKT_user_id`, `IYKT`.`trans_id` AS `IYKT_trans_id`, `IYKT`.`createdon` AS `IYKT_createdon`, `IYKT`.`createdby` AS `IYKT_createdby` FROM `modx_iykt` AS `IYKT` JOIN `modx_user_attributes` `Profile` ON IYKT.user_id = Profile.internalKey "
$c = $modx->newQuery('IYKT');
$c->innerJoin('modUserProfile', 'Profile', array("IYKT.user_id = Profile.internalKey"));
$items = $modx->getCollection('ITYK',$c);
var_dump($c->toSql());
Is there a problem with my schema or is something else going on here?
EDIT 2
I after hours of troubleshooting I finally got the join to work properly. I needed to specifically select the fields I needed from the joined table (I also had to include the ID of the custom table)
public function prepareQueryBeforeCount(xPDOQuery $c) {
$c->innerJoin('modUserProfile','Profile');
$c->select('IYKT.id, Profile.fullname');
$query = $this->getProperty('query');
if (!empty($query)) {
$c->where(array(
'trans_id:LIKE' => '%'.$query.'%',
'OR:Profile.fullname:LIKE' => '%'.$query.'%',
));
}
return $c;
}
[ed. note: betoranaldi last edited this post 11 years, 9 months ago.]