We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17249 ☆ A M B ☆
    • 165 Posts
    Checking at the modx schema to see how it is built i found this uncommon form:

    <aggregate alias="TemplateVars" class="modTemplateVar" local="id:template" foreign="contentid:templateid" cardinality="many" owner="local" />


    What does it means when you use id:template and contentid:templateid?
    Almost any other relation uses single field names.

    This question has been answered by opengeek. See the first response.

      • 18373 ☆ A M B ☆
      • 3,141 Posts
      id=contentid, and template=templateid?

      Just guessing, I never noticed that before either.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        That doesn't look right... I don't think any other aggregate uses colons -- it should be identifying column names, no?
          • 17249 ☆ A M B ☆
          • 165 Posts
          https://github.com/modxcms/revolution/blob/develop/core/model/schema/modx.mysql.schema.xml#L956
          uses this kind of relation



          I have noticed also another thing i haven't seeing in the docs:

                  <composite alias="PropertySets" class="modElementPropertySet" local="id" foreign="element" owner="local" cardinality="many">
                      <criteria target="foreign"><![CDATA[
                      {"element_class":"modPlugin"}
                      ]]></criteria>
                  </composite>
          


          I understand this one, but would like to see more examples/usage.
          This seems to simplify common calls in a CMP but can't find more info about this. [ed. note: lithiumlab last edited this post 13 years, 4 months ago.]
            • 17249 ☆ A M B ☆
            • 165 Posts
            This seems to be related:
            http://tracker.modx.com/issues/2422

              • 42602
              • 81 Posts
              I'd go with Mark's idea also. Had to read the sources as I found the same syntax just while a go but did not have time to read. There is no use for id:template right now. None of the method (getMany, joins, getOne) etc... can understand the colon syntax. Maybe it is something that is under implementation. If you use $resource->getMany('TemplateVars'); it will call internally other function specifically when fetching TemplateVars or modTemplateVar.

              The criteria element is really in simplicity just like that smiley. It adds an extra criteria just like in the example for the join. Great when having same table for many object types so you can have query with "join something on local.id = foreign.id [b]AND foreign.element_class = 'modPlugin'". Best to try it out yourself wink foreign for the extra definition comes from the target attribute. Also any valid JSON array should work but would guess no one has tried it smiley

              The code for the criteria parser looks pretty much like this

              foreach ($fkMeta['criteria']['foreign'] as $critKey => $critVal) {
              	if (is_numeric($critKey)) {
              		$foreignCriteria[] = $critVal;
              	} else {
              		$foreignCriteria["{$parentAlias}.{$critKey}"] = $critVal;
              	}
              }
              


              So if the json would have string, would guess it joins it to query like with joins have the criteria array
              • discuss.answer
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: lithiumlab at Jun 17, 2013, 11:47 AM
                Checking at the modx schema to see how it is built i found this uncommon form:

                <aggregate alias="TemplateVars" class="modTemplateVar" local="id:template" foreign="contentid:templateid" cardinality="many" owner="local">


                What does it means when you use id:template and contentid:templateid?
                Almost any other relation uses single field names.</aggregate>

                It's actually completely meaningless to xPDO, and likely breaks it. In the case of this relationship between Resources and TemplateVars, which is more complicated than a join, all the code has been overridden from the base xPDO behavior going from Resource to TemplateVars. I would ignore the local and foreign definitions in this case as these were authored before the feature introducing the criteria elements within aggregates and composites. We should try to clean this up for 2.3, but even the extended definition doesn't adequately describe the relationship here.

                  • 17249 ☆ A M B ☆
                  • 165 Posts
                  Thanks to all for your detailed answers.
                  I'll dig and try some uses in a custom package i'm currently creating.
                  By fortune, even if i'm no expert in xpdo i do understand why the relationship between Rosource to TemplateVars is more complicated than a join.
                  In fact, i'm currently working in the port of a custom CMS we made years ago in .net to modX where i had to deal with a relation like this one.

                  Until now i was able to pull all the back-end forms with the help of XPDO and MIGXdb.
                  Very happy with the results so far. I encourage all people new to MODx to dig into the core schemas to understand relationships and how they can help create easily maintainable code.

                  Thanks a lot to all the people involved in this awesome cmf called MODx. [ed. note: lithiumlab last edited this post 13 years, 3 months ago.]