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

    I'm using getResources to filter resources with @tvFilters.
    Not all resources that I try to filter do have the TV that is filtered in tvFilters.
    (I want all resources that do not have this TV at all and all where this TV has a special value)

    Shouldn't be any problem I thought, but it seems I can't detect resources without this TV.
    So all resources without this TV are not selected by getResources.
    :-(

    my Question: how do I select these resources, that do NOT even have this TV attached to their template ?
    testing on empty TV-value (&tvFilter=`myTV===||myTV==aValue`) seems not to work.

    TIA

    Marc
      • 5430
      • 247 Posts
      First, the parameter needs to be &tvFilters (with an s) but I'm guessing that's just a typo in your post. Have you tried &tvFilters=`myTV==||myTV==aValue` (== instead of ===)? I've never dealt with this specific scenario but it's possible the &tvFilters parameter is always going to filter resources that don't contain the variable at all in which case you're probably stuck writing a custom snippet.
        • 43568
        • 9 Posts
        hi,

        yes you're right - it's a typo and &tvFilters= is correct.

        when looking into getResources-code, === and == are handled different (one compares and the other uses a LIKE SQL-Statement).

        When getResources always sorts out resources that don't have that specific TV,
        it should be best to add a feature like

        &tvFilters=`!myTV||myTV==value`

        but the questions is: how does getResources handle resources, that do not have the filtered TV attached to it's template ?

        Marc
          • 3749
          • 24,544 Posts
          AFAIK, if the resources don't have that TV, getResources will never look at them.


          Offhand, it seems like it would be very difficult to pull resources that don't have a particular TV.

          One approach would be to connect the TV to the template and put some arbitrary value in it (or leave it blank and search for empty values if none of the real TVs would contain an empty value, using &myTV==``).

          Another way to go would be to query the modTemplateVarResource table one resource at a time and collect resources where either the value is what you're looking for or getObject() for the TVR returns null. The second will get resources without that TV. This would only work if you can use the raw values of the TVs. Note that TVs set to their default value will not have a record in that table, so you'll get them too. The search might be fairly slow.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 43568
            • 9 Posts
            hey,

            so, the main problem is that TVs with default-values are not stored in modTemplateVarResource.
            otherwise we could detect resources that do not have this TV attached to it.

            or we collect all templates that have the TV attached to it,
            compare it to the template of the current resource in question
            and decide based on existence of '!myTV' in &tvFilters whether to continue with normal tvFilters-compares.

            in the end it takes more queries/compares and time. :-(

            BTW:
            when the template of a resource changes, are the attached and stored TV-values updated in modTemplateResource ?
            it looks like that the combination resource/TV and its value keeps stored in the table.

            I think I will go the approach to attach the TV to every possible resource and test for an empty/unset value.

            thx!

            Marc
              • 3749
              • 24,544 Posts
              when the template of a resource changes, are the attached and stored TV-values updated in modTemplateResource ?
              it looks like that the combination resource/TV and its value keeps stored in the table.

              Though TVs have to be connected to a template to show up, the Template has nothing to do with their values. The only three fields in the table that holds the value are 'contentid' (resource ID), 'tmplvarid' (TV ID), and 'value' (value of the TV), so you're correct that they generally maintain their values through Template changes.

              I'm not sure what happens when the TV is not attached to the new Template. I suspect that the values are removed, but I've never checked, since I almost never use TVs for anything.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting