Hi All
Context
I have a request which might be difficult to explain, So i have 3 tables in custom tables that all have relationships with each other. All of the CMPs were made in migxdb and work as expected with no issues what so ever.
The tables are structured as follows.
- A Content table - content
- A Sectors Table - sectors
- Connecting table between the two content_sectors
<?xml version="1.0" encoding="UTF-8"?>
<model package="thing" baseClass="xPDOObject" platform="mysql" defaultEngine="InnoDB" phpdoc-package="thing" phpdoc-subpackage="model" version="1.1">
<object class="content" table="ip_content" extends="xPDOSimpleObject">
<field key="title" dbtype="varchar" precision="191" phptype="string" null="false" default=""/>
<field key="type" dbtype="int" precision="10" phptype="integer" null="false" default=""/>
<field key="deleted" dbtype="int" precision="10" phptype="integer" null="false" default=""/>
<composite alias="sectors" class="content_sectors" local="id" foreign="content_id" cardinality="many" owner="local"/>
</object>
<object class="content_sectors" table="ip_content_sectors" extends="xPDOSimpleObject">
<field key="content_id" dbtype="int" precision="10" phptype="integer" null="false" default=""/>
<field key="sector_id" dbtype="int" precision="10" phptype="integer" null="false" default=""/>
<field key="deleted" dbtype="int" precision="1" phptype="boolean" null="false" default="0"/>
<field key="editedon" dbtype="datetime" phptype="datetime" null="false"/>
<aggregate alias="content_item" class="content" local="content_id" foreign="id" cardinality="one" owner="foreign"/>
<aggregate alias="sector_item" class="sectors" local="sector_id" foreign="id" cardinality="one" owner="foreign"/>
</object>
<object class="sectors" table="ip_sectors" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="50" phptype="string" null="false" default=""/>
<field key="headimg" dbtype="text" phptype="string" null="true" default=""/>
<field key="editedon" dbtype="datetime" phptype="datetime" null="false"/>
<field key="deleted" dbtype="int" precision="10" phptype="integer" null="false" default="0"/>
<composite alias="content" class="content_sectors" local="id" foreign="sector_id" cardinality="many" owner="local"/>
</object>
</model>
The Content table can have many sectors associated with it which works as expected in the CMP
This render chunk might clarify better how im displaying the multiple sectors associated with my content
[[migxLoopCollection?
&packageName=`thing`
&classname=`content_sectors`
&joins=`[{"alias":"sector_item"}]`
&sortConfig=`[{"sortby":"sector_item_name","sortdir":"ASC"}]`
&where=`{"content_id":"[[+id]]","deleted":"0"}`
&tpl=`@CODE:<li >[[+sector_item_name]]</li>`
]]
Issue
The thing im trying to do now is to create a filter that will filter my content table and only show content in my CMP if a sector exists in the connecting “content_sectors” table for the related content_id
I have the Filter Dropdown already by pulling directly from the sectors table
What i need to do now is configure the getlist-where field in migxdb filter to only show content in the CMP when it finds elements in the connecting table that matches the sector_id that i pass through when picking an item in the filter.
most likely i will need to create a new processor for it in addition to the standard getcombo but any pointers or guidance will be massively appreciated.
If it helps anyone i have this functionality working fine in the rest API i created using the syntax below. In this scenario a user can pass through a comma delimited list of sector ids and it will only show the content for it if it finds that content_id existing in the connecting table
$c->leftJoin("content_sectors", "content_sectors", "content.id = content_sectors.content_id");
if ($sssid = (string)$this->getProperty("sectors"))
{
$sectorids = explode(",", $sssid);
$c->where(["content_sectors.sector_id:IN" => $sectorids, "content_sectors.deleted" => 0]);
}