We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48020
    • 3 Posts
    Hello,
    Short question - it there any chance to force MODX to start saving values from multichoice TV as multiple records in DB?
    Eg. I have TV (checkboxes) with 3 values (blue, red yellow).
    When i check only 2 of them MODX saves it in db as "blue||read" (single value) instead of 2 separate records "blue" and "red". Why is that? How can i force it to work as it should smiley ?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      All TVs are saved to the site_tmplvar_contentvalues table, which has four fields, one for ID, one for the TV ID, one for the Resource ID, and one for the value. So there is no place for MODX to store the values except as a delimited string.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 48020
        • 3 Posts
        Ok, but with multiple values we have relationship 1:n, so each value should be stored in single record.
        Please take a look at this case:

        I have a 2 resources containers: Articles and Categories.
        Based on resources under Cetegories container I've created TV "catList". Type checkbox, input value mentioned below:
        @SELECT `pagetitle` AS `name`,`id` FROM `[[+PREFIX]]site_content` WHERE `parent` = 8 AND `published` = 1 AND `deleted` = 0


        Now I have a bunch of articles. Each Article can be assigned to multiple categories.
        Article_1 is assigned to Category_A,Category_D and Category_Z.

        When I open it, I'd like to have in the sidebar list of all articles assigned the the same categories.
        If Article_2 is assigned to Category_B,Category_C and Category_D - I want to show it.
        If Article_3 is assigned to Category_D and Category_Z - I want to show it to.


        With the current method of saving values it is impossible or very difficult.

        With method I've described (1 value => 1 record) its very, very easy:
        SELECT resource_columns FROM resources_table INNER JOIN site_tmplvar_contentvalues ON content_id=resources_table.resource_id
        WHERE tplvarid = 3 AND VALUE IN (here list of all values that i'm interested)