Некорректный подсчет голосов Tickets
Доброго дня коллеги! С помощью mFilter2(&element=`mSearch`) вывожу тикеты, джоином подключил вывод голосов TicketVote:
&leftJoin=`{
"Vote": {
"class": "TicketVote",
"on": "modResource.id = Vote.id AND Vote.class='Ticket'"
}
}`
&select=`{
"modResource": "*",
"Vote" : "SUM(Vote.value) as rating"
}`
в итоге [[+rating]] у первого тикета выводит количество голосов умноженное на 7, у остальных тикетов все верно. Почему так происходит? Комментарии: 4
groupby не забыл?
вот так прописано &groupby=`modResource.id`, не правильно?)
Вроде правильно.
Выведи запрос через showLog и смотри в БД как выполняется и почему.
Выведи запрос через showLog и смотри в БД как выполняется и почему.
Вижу фигу) По запросу все верно вроде, в TiсketVotes всего 5 голосов на 4 ресурса, сейчас у первого тикета в выборке 2 реальных голоса, а отображается 14.
0.0000319: Loaded model "ms2gallery" from "/core/components/ms2gallery/model/"
0.0000119: Loaded model "Tickets" from "/core/components/tickets/model/"
0.0001321: pdoTools loaded.
0.0000250: Loaded model "ms2gallery" from "/core/components/ms2gallery/model/"
0.0000119: Loaded model "Tickets" from "/core/components/tickets/model/"
0.0001252: Query parameters are prepared.
0.0000441: xPDO query object created
0.0006170: Included list of tvs: info_features, info_food, info_open
0.0005271: leftJoined mseIntro as Intro
0.0004740: leftJoined msResourceFile as Image
0.0004709: leftJoined msResourceFile as Thumb
0.0004680: leftJoined TicketVote as Vote
0.0004840: leftJoined modTemplateVarResource as TVinfo_features
0.0004678: leftJoined modTemplateVarResource as TVinfo_food
0.0004730: leftJoined modTemplateVarResource as TVinfo_open
0.0000031: Grouped by modResource.id
0.0003400: Added selection of modResource: SQL_CALC_FOUND_ROWS `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `link_attributes`, `published`, `pub_date`, `unpub_date`, `parent`, `isfolder`, `introtext`, `content`, `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.0000310: Added selection of mseIntro: intro
0.0000248: Added selection of msResourceFile: Image.url as image
0.0000241: Added selection of msResourceFile: Thumb.url as thumb
0.0000730: Added selection of TicketVote: SUM(Vote.value) as rating
0.0000169: Added selection of modTemplateVarResource: IFNULL(`value`, '') AS `info_features`
0.0000150: Added selection of modTemplateVarResource: IFNULL(`value`, '') AS `info_food`
0.0000138: Added selection of modTemplateVarResource: IFNULL(`value`, '') AS `info_open`
0.0000401: Replaced TV conditions
0.0000510: Processed additional conditions
0.0006568: Added where condition: template=6, modResource.id:IN(18,19,20,21), modResource.published=1, modResource.deleted=0
0.0000391: Replaced TV conditions
0.0002019: Sorted by FIELD(`modResource`.`id`,'18','19','20','21'),
0.0000060: Limited to 10, offset 0
0.0005322: SQL prepared "SELECT SQL_CALC_FOUND_ROWS `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`link_attributes`, `modResource`.`published`, `modResource`.`pub_date`, `modResource`.`unpub_date`, `modResource`.`parent`, `modResource`.`isfolder`, `modResource`.`introtext`, `modResource`.`content`, `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`, `intro`, Image.url as image, Thumb.url as thumb, SUM(Vote.value) as rating, IFNULL(`TVinfo_features`.`value`, '') AS `info_features`, IFNULL(`TVinfo_food`.`value`, '') AS `info_food`, IFNULL(`TVinfo_open`.`value`, '') AS `info_open` FROM `modx_site_content` AS `modResource` LEFT JOIN `modx_mse2_intro` `Intro` ON `modResource`.`id`=`Intro`.`resource` LEFT JOIN `modx_ms2_resource_files` `Image` ON modResource.id = Image.resource_id AND Image.parent = 0 LEFT JOIN `modx_ms2_resource_files` `Thumb` ON Image.id = Thumb.parent AND Thumb.path LIKE '%376x268%' LEFT JOIN `modx_tickets_votes` `Vote` ON modResource.id = Vote.id AND Vote.class='Ticket' LEFT JOIN `modx_site_tmplvar_contentvalues` `TVinfo_features` ON `TVinfo_features`.`contentid` = `modResource`.`id` AND `TVinfo_features`.`tmplvarid` = 17 LEFT JOIN `modx_site_tmplvar_contentvalues` `TVinfo_food` ON `TVinfo_food`.`contentid` = `modResource`.`id` AND `TVinfo_food`.`tmplvarid` = 13 LEFT JOIN `modx_site_tmplvar_contentvalues` `TVinfo_open` ON `TVinfo_open`.`contentid` = `modResource`.`id` AND `TVinfo_open`.`tmplvarid` = 7 WHERE ( `modResource`.`template` = 6 AND `modResource`.`id` IN (18,19,20,21) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 ) GROUP BY modResource.id ORDER BY FIELD(`modResource`.`id`,'18','19','20','21') LIMIT 10 "
0.0001862: SQL executed
0.0002110: Total rows: 4
0.0000610: Rows fetched
0.0002470: Returning raw data
0.0015321: Loaded chunk "tpl.mSearch2.row.custom"
0.0014811: Compiled Fenom chunk with name "chunk/70"
0.0608928: Returning processed chunks
0.0718839: Total time
23 592 960: Memory usage
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.