[2016-12-29 12:46:58] (ERROR @ /var/www/public/modx-te/public_html/core/xpdo/om/xpdoobject.class.php : 240) Error 42S22 executing statement: Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'Country.id' in 'field list' )
<object class="LocationsCountry" table="locations_country" extends="xPDOSimpleObject"> <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" /> <field key="position" dbtype="int" precision="10" phptype="integer" null="false"/> <composite alias="CountryProfile" class="LocationsCountryProfile" local="id" foreign="internalKey" cardinality="one" owner="local" /> </object> <object class="LocationsCountryProfile" table="locations_country_profile" extends="xPDOSimpleObject"> <field key="internalKey" dbtype="int" precision="10" phptype="integer" null="false" index="unique" /> <field key="description" dbtype="text" phptype="text" null="false" default="" /> <index alias="internalKey" name="internalKey" primary="false" unique="true" type="BTREE"> <column key="internalKey" length="" collation="A" null="false" /> </index> <aggregate alias="Country" class="LocationsCountry" local="internalKey" foreign="id" cardinality="one" owner="foreign" /> </object>
<?php /** * Get a list of Countries * * @package locations * @subpackage processors */ class LocationsCountryGetListProcessor extends modObjectGetListProcessor { public $classKey = 'LocationsCountry'; public $languageTopics = array('locations:default'); public $defaultSortField = 'position'; public $defaultSortDirection = 'ASC'; public $objectType = 'locations.country'; public function prepareQueryBeforeCount(xPDOQuery $c) { $c->leftJoin('LocationsCountryProfile','CountryProfile'); $query = $this->getProperty('query'); if (!empty($query)) { $c->where(array( 'Country.name:LIKE' => '%'.$query.'%' )); } return $c; } public function prepareQueryAfterCount(xPDOQuery $c) { $c->select($this->modx->getSelectColumns('LocationsCountry','Country')); $c->select($this->modx->getSelectColumns('LocationsCountryProfile','CountryProfile')); return $c; } } return 'LocationsCountryGetListProcessor';
This question has been answered by muzzstick. See the first response.
<?php /** * Get a list of Countries * * @package locations * @subpackage processors */ class LocationsCountryGetListProcessor extends modObjectGetListProcessor { public $classKey = 'LocationsCountry'; public $languageTopics = array('locations:default'); public $defaultSortField = 'position'; public $defaultSortDirection = 'ASC'; public $objectType = 'locations.country'; public function prepareQueryBeforeCount(xPDOQuery $c) { $c->leftJoin('LocationsCountryProfile','CountryProfile'); $c->select($this->modx->getSelectColumns('LocationsCountryProfile','CountryProfile')); $query = $this->getProperty('query'); if (!empty($query)) { $c->where(array( 'name:LIKE' => '%'.$query.'%' )); } return $c; } } return 'LocationsCountryGetListProcessor';
<?php /** * Get a list of Countries * * @package locations * @subpackage processors */ class LocationsCountryGetListProcessor extends modObjectGetListProcessor { public $classKey = 'LocationsCountry'; public $languageTopics = array('locations:default'); public $defaultSortField = 'position'; public $objectType = 'locations.country'; public function prepareQueryBeforeCount(xPDOQuery $c) { $c->leftJoin('LocationsCountryProfile','CountryProfile'); $c->select('LocationsCountry.id,name,position'); $c->select($this->modx->getSelectColumns('LocationsCountryProfile','CountryProfile','',array('description'))); $query = $this->getProperty('query'); if (!empty($query)) { $c->where(array( 'LocationsCountry.name:LIKE' => '%'.$query.'%' )); } return $c; } } return 'LocationsCountryGetListProcessor';
$c->select($this->modx->getSelectColumns('LocationsCountry','Country','',array('id','name','position')));
$c->leftJoin('LocationsCountryProfile','CountryProfile', 'CountryProfile.country_id = LocationsCountry.id');