We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7858
    • 97 Posts
    Hi,

    i need to select resources based on condition that array (generated based on resource TV) includes some value.

    Something like

     &where=`{"2:IN":[[!catArray? &input=`[[+tv.Category]]`]]}`


    but it does not work. How can I get it work?

    The idea is to create some categories in my blog. So i've created some MIGx TV for parent resource. In this TV I list all my categories. TV values are parsed to children resources TVs as multiselect lists. So user can select to which categories this resource belongs.

    And then I do want to select recources from only one category with getResources. But I can't figure out how to write select condition.

    Thx
      • 4172
      • 5,888 Posts
      hmm.... not really sure, what you did. Some more code for us?
      And perhaps the output of
      [[+tv.Category]]


      where do you have this &where ?
      Perhaps the complete snippet-tag, if possible and where you have it.
      In a getResources-tpl-chunk ? If yes, what's your outer getResources - tag?

      we developers like to read more code, less text!
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 7858
        • 97 Posts
        hi,

        this is a full call

        [[!getResources? &parents=`2` &showHidden=`1` &tpl=`ArticleRowTpl` &includeTVs=`1` &where=`{"2:IN":[[!catArray? &input=`[[+tv.Category]]`]]}`]]


        as an output of

        [[!catArray? &input=`[[+tv.Category]]`]]


        I become array in form [1,2] (migx id's for categories)

        I need to select only resources that have values in their arrays that i want to load fot this page. In my example - 2.
          • 22303 MODX Staff
          • 10,725 Posts
          All this would do (if it were a valid expression, which I don't believe it is because the key is expected to be a field name, not a scalar value) is add a WHERE clause to the SELECT which would say:

          WHERE 2 IN (1,2)

          This would always be true and everything would be selected, unless 2 is not in that list. In which case, nothing would be selected.
            • 7858
            • 97 Posts
            Yes, you are right. But how can I do it in a right way?

            How to tell

            where one of the array elements (stored in TV) equals to 2? [ed. note: dopeless last edited this post 13 years, 11 months ago.]
              • 22303 MODX Staff
              • 10,725 Posts
              TV values can only be used for filtering results from the unprocessed data stored for each Resource, via the tvFilters and related properties in getResources. But to be honest, searching and filtering results on data that is stored in a single database column in various formats, like MIGX does, is not an efficient way of selecting data. You may be better off creating a custom Snippet for this purpose or considering storing your data in a normalized fashion outside of MODX Resources and Template Variables for more efficient searching, sorting, and view presentation.