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

    I have a special case where I need to create a where clause with following conditions:

    I have left joined a TV to the modResource table.
    The value field of the TV has comma separated ids in it.
    And I have an array which also holds a list of ids.

    (CategoryTV.value holds comma seperated values and $arrCatIDs holds list of ids)

    I'd like to get all rows where 'one or many' ids of the TV are equal to 'one or many' ids from the array.
    The IN operator doesn't work here.
    Is this a relational division? And if so, how can I solve this with xPDO?

    Thanks,
    Martin
      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
      • 22303 MODX Staff
      • 10,725 Posts
      Sounds like you might have to use a MySQL specific function like FIND_IN_SET() to solve this, in which case, you would just pass that as a string condition to your query, either in the where, or preferably, in the join conditions for the TV.
        • 3749
        • 24,544 Posts
        Can you describe what it is you're trying to get? I can't quite puzzle it out from your description. The IDs in the TV are IDs of what object? And IDs in the array are IDs of what object?

        If you just want all Resources with IDs in either array, you shouldn't need a join.

          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
          • 10378
          • 375 Posts
          OK - I try to find a better explanation:

          I have a resource inside an Articles container - lets say Articles1 - with an attached TV called Categories. This TV contains a comma separated list of category IDs from a custom table.
          The same resource has attached another TV called SelectNews (which calls a snippet). This TV should list a group of resources from another Articles container - lets say Articles2 - based on the selection of one or many category IDs from the Categories TV.

          The resources from Articles2 also have attached the CategoriesTV and one or many categories can be selected there.

          I'd like to get all resources from container Articles2 where 'one or many' category IDs are equal to 'one or many' category ids from the selected ones in the first resource.

          I think the confusion is perfect now, but I don't know how to explain this better. Sorry.
            Freelancer @bitego http://www.bitego.com
            ---
            GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
            More infos here: http://www.bitego.com/extras/goodnews/
            • 4172
            • 5,888 Posts
            I would create a join-table where you have collected all relations between categories and resources.
            You can syncronize this table with your TVs by onDocFormSave.

            Than its easy to get all Resources, which are at least in one of a given list of resource-ids.

            Would also be possible to use a MIGXdb-grid-TV to add/remove category-links
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!