M
M
Michael2014-07-12 01:05:42
MODX
Michael, 2014-07-12 01:05:42

How to draw up a diagram for the model and use it?

There are two models: forum section and forum topic.
You need to display a list of recent topics.
Partition scheme:

<object class="ForumSections" table="forum_sections" extends="xPDOSimpleObject">
  <field key="title" dbtype="varchar" precision="32" phptype="string" null="false" />
  <field key="alias" dbtype="varchar" precision="16" phptype="string" null="false" />
</object>

Topic scheme (simplified):
<object class="ForumTopics" table="forum_topics" extends="xPDOSimpleObject">
  <field key="section" dbtype="tinyint" precision="3" attributes="unsigned" phptype="integer" null="false" />
  <field key="author" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
  <field key="title" dbtype="varchar" precision="255" phptype="string" null="false" />
</object>

What needs to be added to schema files to compose the query below?
SELECT * FROM `modx_forum_topics` JOIN `modx_forum_sections` ON `modx_forum_topics`.`section` = `modx_forum_sections`.`id`

And how to make a request through xPDO?
I read the manual from Bob, as well as the documentation, but I was already confused about what went where.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alvisX, 2014-07-12
@alvisX

On a good note, links (composite or aggregate) need to be added to the schema. Then generate automatically or manually map files. After that, objects can be obtained like this:

$TopicSection= $xpdo->getObject('TopicSection',$id);
$Topics= $TopicSection->getMany('Topics');

1. Create tables in the database with your hands
2. Generate a schema from them (tables), for example, using the CMP Generator extension from the repository
3. Add links to the schema (more details here )
4. Regenerate the model using the same CMP Generator, unchecking "Build schema", otherwise the schema will be overwritten
Now you can get any object using getObject and its dependencies using getOne and getMany

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question