We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51292
    • 18 Posts
    I am using the latest unmodified version of getResources. The query it is generating for this code:
    [[!getResources ? &debug=`1`]]


    Is incorrectly adding
     modResource.parent IN (1,2,3)
    preventing my actual resources from getting queried.

    You can see my basic resource tree below:


    This should be returning resource id of 9 (Testing Scenario), but it only returns resources 2 and 3 (because of the parent in the query).

    SELECT `modResource`.`id`, 
           `modResource`.`type`, 
           `modResource`.`contenttype`, 
           `modResource`.`pagetitle`, 
           `modResource`.`longtitle`, 
           `modResource`.`description`, 
           `modResource`.`alias`, 
           `modResource`.`link_attributes`, 
           `modResource`.`published`, 
           `modResource`.`pub_date`, 
           `modResource`.`unpub_date`, 
           `modResource`.`parent`, 
           `modResource`.`isfolder`, 
           `modResource`.`introtext`, 
           `modResource`.`richtext`, 
           `modResource`.`template`, 
           `modResource`.`menuindex`, 
           `modResource`.`searchable`, 
           `modResource`.`cacheable`, 
           `modResource`.`createdby`, 
           `modResource`.`createdon`, 
           `modResource`.`editedby`, 
           `modResource`.`editedon`, 
           `modResource`.`deleted`, 
           `modResource`.`deletedon`, 
           `modResource`.`deletedby`, 
           `modResource`.`publishedon`, 
           `modResource`.`publishedby`, 
           `modResource`.`menutitle`, 
           `modResource`.`donthit`, 
           `modResource`.`privateweb`, 
           `modResource`.`privatemgr`, 
           `modResource`.`content_dispo`, 
           `modResource`.`hidemenu`, 
           `modResource`.`class_key`, 
           `modResource`.`context_key`, 
           `modResource`.`content_type`, 
           `modResource`.`uri`, 
           `modResource`.`uri_override`, 
           `modResource`.`hide_children_in_tree`, 
           `modResource`.`show_in_tree`, 
           `modResource`.`properties` 
    FROM   `modx_site_content` AS `modResource` 
    WHERE  ( modresource.parent IN ( 1, 2, 3 ) 
             AND `modResource`.`deleted` = 0 
             AND `modResource`.`published` = 1 
             AND `modResource`.`hidemenu` = 0 ) 
    ORDER  BY publishedon DESC 
    LIMIT  5 

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

      • 51292
      • 18 Posts
      I see now that it defaults to include the resource page that you are currently loading as a parent, but this seems like very odd default behavior to me, as I am likely to query entirely different content to display on this page.

      I've had to heavily modify the getResources plugin to prevent this, as the rest of the plugin assumes that you are querying for parents. [ed. note: dallen last edited this post 10 years, 11 months ago.]
        • 30585
        • 833 Posts
        Not sure I really understand your concern, but the purpose of getResources is to aggregate resources. The &parents property is where it looks for children resource to list. It rightfully assumes that the current resource is the parent, when none other is specified, partly because it's what most developers expect it to do. I see no need for you to modify the source code if all you want is to include resource 9.

        Here are a few use cases:
        // This will return resources 2 and 3 and 9
        [[getResources? &parents=`1` &resources=`9` &tpl=`myRowTpl`]]
        // This will return all resources in the tree -- web context
        [[getResources? &parents=`0` &tpl=`myRowTpl`]]
        


        BTW the &debug is only used for debugging purposes. So no need to include it in your call, unless that's what you want. Also, you should also include a chunk to template your results in the &tpl property. The documentation explains things much better than me and has lots of examples: https://rtfm.modx.com/extras/revo/getresources
          A MODx Fanatic
        • discuss.answer
          • 51292
          • 18 Posts
          I don't think it rightfully assumes that, and the fact that it makes that assumption with no way around it save for modifying the snippet is shortsighted and inflexible. If i'm on a page, for example, the about page, and I want to query testimonials to display, I would not nest these testimonials under the about page, because they don't belong there in the hierarchy, however it is something that I want to be able to do. And what would happen if I want to display these testimonials on a totally different page? I can't nest the content under two parents, and having to build a nasty content hierarchy to do this isn't a solution, but is a workaround.

          Additionally I am aware of all of the other parameters you can pass to getResources, they are removed to simplify the query to make it easier to find the issue. The debug is there to spit out the query in the first place.
            • 4172
            • 5,888 Posts
            this

            modResource.parent IN (1,2,3)


            is absolutely correct behavior.

            Get all Resources, which have the current resource and all sub-resources as parent.
            This doesn't get the current resource.
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 51292
              • 18 Posts
              I'm not trying to get the current resource, it's trying to query resources that are unrelated (hierarchically) to the current resource. In my example above, the current resource could be the about page, and the resource I'm trying to query is a testimonial. They are hierarchically unrelated, but I need to display the content on that page. With getResources as it is, that is impossible without creating a work around by adding these items as children of the About Us page, and even then, if I ever wanted to query the testimonials somewhere else, I couldn't because they would belong under the about us page.

              None of this matters, since I've updated getResources to do what I need it to do.
                • 4172
                • 5,888 Posts
                I hope, you did modify a copy of getResources, otherwise your mods will get overridden on upgrades.
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 30585
                  • 833 Posts
                  Let's consider the following tree structure:

                  ├── Home (1)
                  │   ├── Home Facebook (2)
                  │   ├── Home Google (3)
                  ├── Testing Scenario (9)
                  ├── Product Overview (7)
                  │   ├── Product 1 (8)
                  │   ├── Product 2 (10)
                  │   ├── Product ... (11)
                  ├── About (12) // Has the getResources call
                  ├── Testimonial (13) // The resource whose children we're aggregating 
                  │   ├── Testimonial 1 (14)
                  │   ├── Testimonial 2 (15)
                  │   ├── Testimonial 3 (16)
                  


                  Placing the following getResources call on your about page would list all resources under Testimonial -- which sounds like what you're describing.
                  [[getResources? &parents=`13` &limit=`10` &tpl=`myRowTpl`]]
                  

                  In this example, resources 12 and 13 are unrelated as you can see and we can still list the children of resource 13 on resource 12. No hacks, no rewrites.

                  Perhaps there's a misunderstanding somewhere, but getResources is behaving exactly as intended. By "hierarchically unrelated" do you mean that these resources are on a separate db table or are they just under another container in the same tree?
                    A MODx Fanatic
                    • 51292
                    • 18 Posts
                    treigh, while that works, I think that I have a fundamental disagreement with the way that getResources functions, and I don't think that it should be up to the content editor to have to know the id of the parent(s) for which those resources reside, and would also require every single getResource call that queried testimonials to be updated if we changed the content hierarchy, when the hierarchy of the data should be independent of the way in which data is queried.

                    Like I mentioned, it doesn't matter now, as I have modified the plugin to act the way that I think it should act, and my content will be all the more flexible for it.
                      • 30585
                      • 833 Posts
                      Glad to see it's working for you.

                      I don't mean to be dragging this, but I'm sensing light at the end of the tunnel if you see what I mean. when you have time, why don't you describe your exact use case. I can almost swear that we can sort it out without having to touch the source code. Let's do this at least for the benefit of the community -- someone else could be facing the same issue one day.

                      Cheers!
                        A MODx Fanatic