where по одному полю для двух ресурсов

Здравствуйте!

Хочу сделать связь ресурсов по одному полю.
Имею поле connection, в котором множественный выбор.
Это поле добавляется абсолютно ко всем ресурсам. И пытаюсь организовать связь ресурсов.

'where' => '{"connection":[[*connection]]}'
Т.е., если у ресурсов сделан одинаковый выбор, то есть возможность вывести ссылку друг на друга.
Но данная схема не работает:
'where' => '{"connection":[[*connection]]}'
Может так вообще делать нельзя.

Вот весь мой код вывода связи ресурсов:
{var $output = 'ms2GalleryResources' | snippet: [
    'tpl' => 'proekt-item-portfolio'
    'parents' => '394'
    'where' => '{"connection":"[[*connection]]","connection.value:!=":1 }'
    'limit' => '6'
    'includeThumbs' => 'medium'
    'includeTVList' => 'days, connection, video'
    'depth' => '0'
    'showLog' => '1'
]}
{if $output}
<h3 class="text-center">[[*connection]] в наличии</h3>
<div class="row flex-content-center">
{$output}
</div>
{/if}
Илья
27 мая 2024, 17:42
modx.pro
220
0

Комментарии: 6

Артур Шевченко
27 мая 2024, 18:33
+1
Скорее всего нужно использовать FIND_IN_SET
    Алексей Смирнов
    27 мая 2024, 23:13
    +1
    Вы мешаете синтаксис фенома и phx MODX.
    Запишите все на феноме для начала:
    {var $output = 'ms2GalleryResources' | snippet: [
        'tpl' => 'proekt-item-portfolio',
        'parents' => '394',
        'where' => '{ "connection:=":"'~$_modx->resource.connection~'","connection:!=":"1"}',
        'limit' => '6',
        'includeThumbs' => 'medium',
        'includeTVList' => 'days, connection, video',
        'depth' => '0',
        'showLog' => '1'
    ]}
    {if $output}
    <h3 class="text-center">{$_modx->resource.connection} в наличии</h3>
    <div class="row flex-content-center">
    {$output}
    </div>
    {/if}
    и если не сработает можно двигаться дальше.
    например у вас гарантированно в ТВ поле connection Находится один id? те там нет двух или трех id через запятую?
      Илья
      28 мая 2024, 10:19
      0
      Спасибо! Этот вариант работает.

      т.е. там нет двух или трех id через запятую
      Да, может быть несколько ID. Подскажите, в этом случае только через FIND_IN_SET?
        Алексей Смирнов
        28 мая 2024, 10:31
        +1
        да в этом случае необходимо воспользоваться информацией которая тут: ссылка на многотекстаиполезного #23005
          Илья
          28 мая 2024, 13:56
          0
          Посмотрите пожалуйста:
          Не могу разобраться, ругается на синтаксис. У меня сайт на fenom. В стандартной транскрипции работает, а в fenom выдаёт ошибку. Всё перепробовал, в глазах рzбит.

          Работает:

          [[!ms2GalleryResources?
              &tpl=`proekt-item-portfolio`
              &parents=`394`
              &limit=`6`
              &where=`["1 = 1 AND FIND_IN_SET('[[*portfolio_item]]', replace(portfolio_item, '||', ','))"]`
              &includeThumbs=`medium`
              &includeTVs=`portfolio_item`
              &depth=`0`
              &showLog=`1`
          ]]

          Не работает:

          {'!ms2GalleryResources' | snippet : [
              'tpl' => 'proekt-item-portfolio'
              'parents' => '394'
              'limit' => '6'
              'where' => ["1 = 1 AND FIND_IN_SET("~$_modx->resource.portfolio_item~", replace(portfolio_item, '||', ','))"],
              'includeThumbs' => 'medium'
              'includeTVList' => 'portfolio_item'
              'depth' => '0'
              'showLog' => '1'
          ]}
          showLog:
          0.0000520: Loaded model "ms2gallery" from "/core/components/ms2gallery/model/"
          0.0000269: pdoTools loaded
          0.0000110: xPDO query object created
          0.0002151: Included list of tvs: portfolio_item
          0.0000780: leftJoined msResourceFile as medium
          0.0000532: leftJoined modTemplateVarResource as TVportfolio_item
          0.0000861: Added selection of modResource: `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `alias_visible`, `link_attributes`, `published`, `pub_date`, `unpub_date`, `parent`, `isfolder`, `introtext`, `richtext`, `template`, `menuindex`, `searchable`, `cacheable`, `createdby`, `createdon`, `editedby`, `editedon`, `deleted`, `deletedon`, `deletedby`, `publishedon`, `publishedby`, `menutitle`, `donthit`, `privateweb`, `privatemgr`, `content_dispo`, `hidemenu`, `class_key`, `context_key`, `content_type`, `uri`, `uri_override`, `hide_children_in_tree`, `show_in_tree`, `properties`
          0.0000072: Added selection of msResourceFile: `url` as `medium`,`name` as `medium.name`,`description` as `medium.description`,`createdon` as `medium.createdon`,`createdby` as `medium.createdby`,`properties` as `medium.properties`,`alt` as `medium.alt`,`add` as `medium.add`
          0.0000041: Added selection of modTemplateVarResource: IFNULL(`value`, '') AS `tv.portfolio_item`
          0.0000072: Replaced TV conditions
          0.0004930: Processed additional conditions
          0.0005889: Added where condition: 0=1 = 1 AND FIND_IN_SET(Блок-контейнеры, replace(`TVportfolio_item`.`value`, '||', ',')), modResource.parent:IN(394), modResource.published=1, modResource.deleted=0
          0.0000019: Replaced TV conditions
          0.0000300: Sorted by modResource.publishedon, DESC
          0.0000010: Limited to 6, offset 0
          0.0001161: SQL prepared "SELECT `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`alias_visible`, `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`, `medium`.`url` as `medium`, `medium`.`name` as `medium.name`, `medium`.`description` as `medium.description`, `medium`.`createdon` as `medium.createdon`, `medium`.`createdby` as `medium.createdby`, `medium`.`properties` as `medium.properties`, `medium`.`alt` as `medium.alt`, `medium`.`add` as `medium.add`, IFNULL(`TVportfolio_item`.`value`, '') AS `tv.portfolio_item` FROM `kfsz8k4f2Ra7_site_content` AS `modResource` LEFT JOIN `kfsz8k4f2Ra7_ms2_resource_files` `medium` ON `medium`.`resource_id` = `modResource`.`id` AND `medium`.`parent` != 0 AND `medium`.`path` LIKE '%/medium/%' AND `medium`.`active` = 1 AND `medium`.`rank` = 0 LEFT JOIN `kfsz8k4f2Ra7_site_tmplvar_contentvalues` `TVportfolio_item` ON `TVportfolio_item`.`contentid` = `modResource`.`id` AND `TVportfolio_item`.`tmplvarid` = 19 WHERE  ( 1 = 1 AND FIND_IN_SET(Блок-контейнеры, replace(`TVportfolio_item`.`value`, '||', ',')) AND `modResource`.`parent` IN (394) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 )  ORDER BY modResource.publishedon DESC LIMIT 6 "
          0.0002279: Could not process query, error #1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Блок-контейнеры, replace(`TVportfolio_item`.`value`, '||', ',')) AND `modResource`.`pa' at line 1
          0.0015500: Total time
          2 097 152: Memory usage
            Алексей Смирнов
            28 мая 2024, 14:48
            +1
            'where' => [0 => "0 < FIND_IN_SET(" ~ $_modx->resource.id~ ", replace(`TVportfolio_item`.`value`, '||', ','))"]
            Тут $_modx->resource.id — id текущего ресурса (тот к которому будем искать в сторонних ресурсах значения в ТВ-шке portfolio_item, внимательно смотрите на особенности записи ТВ в запросах where.
      Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
      6