Z
Z
z00912014-02-05 18:33:41
MODX
z0091, 2014-02-05 18:33:41

How to make a selection with a where condition for composite links in modx revo?

Hello!
There was a question on xPDO in Modx Revo.
There are 2 tables.

<object class="CatalogmanagerItem" table="catalogmanager_item" extends="xPDOSimpleObject">
    <field key="type" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
    <field key="pagetitle" dbtype="varchar" precision="255" phptype="string" null="false" />
    <field key="parentid" dbtype="int" precision="10" phptype="integer" null="false" default="0" index="index" />
    <field key="menuindex" dbtype="int" precision="20" phptype="integer" null="false" />
    <field key="active" dbtype="tinyint" precision="1" phptype="integer" null="false" default="1" />
    <field key="delete_object" dbtype="tinyint" precision="1" phptype="integer" null="false" default="0" />
    <field key="class" dbtype="varchar" precision="50" phptype="string" null="true" />

    <index alias="parentid" name="parentid" primary="false" unique="false" type="BTREE" >
      <column key="parentid" length="" collation="A" null="false" />
    </index>

    <composite alias="Data" class="CatalogmanagerXtype" local="id" foreign="object_id" cardinality="many" owner="local" />
  </object>

<object class="CatalogmanagerXtype" table="catalogmanager_xtype" extends="xPDOSimpleObject">
    <field key="object_id" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" />
    <field key="type" dbtype="varchar" precision="100" phptype="string" null="false" />
    <field key="value" dbtype="longtext" phptype="string" null="true" />
    <field key="key" dbtype="varchar" precision="255" phptype="string" null="true" />
    <field key="xtype" dbtype="varchar" precision="255" phptype="string" null="false" />

    <index alias="object_id" name="object_id" primary="false" unique="false" type="BTREE" >
      <column key="object_id" length="" collation="A" null="false" />
    </index>

    <aggregate alias="Item" class="CatalogmanagerItem" local="object_id" foreign="id" cardinality="one" owner="foreign" />
  </object>

How can I select all objects that have parentid=0, active=1, delete_object=0 and in table catalogmanager_xtype key='alias', value='modx'.
Right now I'm doing something like this:
$objectArray = array();

$w = array('parentid'=>0, 'active'=>1, 'delete_object'=>0);
$Collection = $this->modx->getCollection('CatalogmanagerItem', $w );

foreach ($Collection as $object) {
      $data = $object->toArray();
      $fields = $object->getMany('Data');
            if ($fields) {
                foreach ($fields as $field) {
                    $data[$field->key] = $field->value;
                }
            }
      if ($data['alias'] == 'modx') $objectArray[] = $data;
}

But as you can see, this is completely inconvenient. Please tell me the best way to do this!
It would be desirable to display all conditions in one where.
Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question