1

We migrated a craft cms site with 3 locales from v2.9 to 3.5 We have a section with a field of type "Entries". When editing the entry, and adding certain entries to this field, those get added twice after saving. After investigating, these relations dont show up twice in DB, but the SQL-query returns them twice.

i created a test template to narrow down the SQL:

{% set infos = craft.entries.id(497).one().contextInterneLinksRel.all() %}

the sql resulting into double showing the relation:

SELECT `elements`.`id`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`id` AS `siteSettingsId`, `elements_sites`.`slug`, `elements_sites`.`siteId`, `elements_sites`.`uri`, `elements_sites`.`enabled` AS `enabledForSite`, `entries`.`sectionId`, `entries`.`typeId`, `entries`.`authorId`, `entries`.`postDate`, `entries`.`expiryDate`, `content`.`id` AS `contentId`, `content`.`title`, `content`.`field_absenderAuthorText`, `content`.`field_adminSpracheinstellungen`, `content`.`field_aktuellerStatus`, `content`.`field_medienmitteilungAnriss`, `content`.`field_showInList`, `content`.`field_begruessungstext`, `content`.`field_betreff`, `content`.`field_copyrightInformationenIntranet`, `content`.`field_medienmitteilungDatumVeroeffentlichung`, `content`.`field_deMailchimpNewsletterGdpr`, `content`.`field_deMailchimpNewsletterHoneypot`, `content`.`field_deMailchimpNewsletterUrl`, `content`.`field_globalEmailKursanmeldungenAlternativ`, `content`.`field_einleitungstext`, `content`.`field_globalAdresse`, `content`.`field_fileAlt`, `content`.`field_automatischesInhaltsverzeichnis`, `content`.`field_forumRBeschreibung`, `content`.`field_adminBildFocusCSSPosition`, `content`.`field_noTransform`, `content`.`field_blogAnrissText`, `content`.`field_fileCopyright`, `content`.`field_fileDescription`, `content`.`field_definitiveAnmeldung`, `content`.`field_einfacherInhalt`, `content`.`field_globalEmailKursanmeldungen`, `content`.`field_globalEmailVeranstaltungsanmeldungen`, `content`.`field_contextExterneLinks`, `content`.`field_portalLinkUrl`, `content`.`field_forumRAusgabe`, `content`.`field_kampagnenBoxInhalt`, `content`.`field_kampagnenBoxLink`, `content`.`field_kampagnenBoxLinkText`, `content`.`field_keineAnmeldungMoeglich`, `content`.`field_keinHeaderBild`, `content`.`field_kontaktFuerKurse`, `content`.`field_kontaktFuerVeranstaltungen`, `content`.`field_kostenMitglied`, `content`.`field_kostenNichtMitglied`, `content`.`field_kursKosten`, `content`.`field_notShowInNav`, `content`.`field_portalInhalt`, `content`.`field_portalLinkText`, `content`.`field_portalTitel`, `content`.`field_produktBeschreibung`, `content`.`field_produktPreis`, `content`.`field_produktReferenznummer`, `content`.`field_produktSteuer`, `content`.`field_globalRechteSpalteFusszeile`, `content`.`field_redirectUrl`, `content`.`field_regionkuerzel`, `content`.`field_seitenLayout`, `content`.`field_seitenueberschrift`, `content`.`field_metatagDescription`, `content`.`field_seitezugriffe`, `content`.`field_metatagTitle`, `content`.`field_frMailchimpNewsletterGdpr`, `content`.`field_frMailchimpNewsletterHoneypot`, `content`.`field_frMailchimpNewsletterUrl`, `content`.`field_fragenBemerkungen`, `content`.`field_itMailchimpNewsletterGdpr`, `content`.`field_itMailchimpNewsletterHoneypot`, `content`.`field_itMailchimpNewsletterUrl`, `content`.`field_newsletterausgabe`, `content`.`field_isShopStartseite`, `content`.`field_sprachenAbgeschlossen`, `content`.`field_subnavigationImmerZeigen`, `content`.`field_suchresultatText`, `content`.`field_test`, `structureelements`.`root`, `structureelements`.`lft`, `structureelements`.`rgt`, `structureelements`.`level`, `structureelements`.`structureId`
FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `elementsSitesId`, `content`.`id` AS `contentId`, `structureelements`.`structureId`
FROM `rhe_elements` `elements`
INNER JOIN `rhe_entries` `entries` ON `entries`.`id` = `elements`.`id`
INNER JOIN `rhe_elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id`
INNER JOIN `rhe_content` `content` ON (`content`.`elementId` = `elements`.`id`) AND (`content`.`siteId` = `elements_sites`.`siteId`)
LEFT JOIN `rhe_structureelements` `structureelements` ON (`structureelements`.`elementId` = `elements`.`id`) AND (EXISTS (SELECT *
FROM `rhe_structures`
WHERE (`id` = `structureelements`.`structureId`) AND (`dateDeleted` IS NULL)))
INNER JOIN `rhe_relations` `relations` ON (`relations`.`targetId` = `elements`.`id`) AND ((`relations`.`sourceId`=497) AND (`relations`.`fieldId`='85')) AND ((`relations`.`sourceSiteId` IS NULL) OR (`relations`.`sourceSiteId`=1))
WHERE (`elements_sites`.`siteId`=1) AND (`elements`.`archived`=FALSE) AND (((`elements`.`enabled`=TRUE) AND (`elements_sites`.`enabled`=TRUE)) AND (`entries`.`postDate` <= '2020-11-24 15:05:00') AND ((`entries`.`expiryDate` IS NULL) OR (`entries`.`expiryDate` > '2020-11-24 15:05:00'))) AND (`elements`.`dateDeleted` IS NULL) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId` IS NULL)
ORDER BY `relations`.`sortOrder`) `subquery`
INNER JOIN `rhe_entries` `entries` ON `entries`.`id` = `subquery`.`elementsId`
INNER JOIN `rhe_elements` `elements` ON `elements`.`id` = `subquery`.`elementsId`
INNER JOIN `rhe_elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`elementsSitesId`
INNER JOIN `rhe_content` `content` ON `content`.`id` = `subquery`.`contentId`
LEFT JOIN `rhe_structureelements` `structureelements` ON (`structureelements`.`elementId` = `subquery`.`elementsId`) AND (`structureelements`.`structureId` = `subquery`.`structureId`)
INNER JOIN `rhe_relations` `relations` ON (`relations`.`targetId` = `elements`.`id`) AND ((`relations`.`sourceId`=497) AND (`relations`.`fieldId`='85')) AND ((`relations`.`sourceSiteId` IS NULL) OR (`relations`.`sourceSiteId`=1))
ORDER BY `relations`.`sortOrder`

Here is an example for a double from the result:

enter image description here

The only difference are in columns: root,lft,rgt,structureId the rest is all the same.

enter image description here

It seems there are 2 rows in table structureelements for this entry, that gets added twice.

enter image description here

What does it mean? Any help is apreciated, thx.

3
  • 2
    Back up and try running ./craft utils/repair/section-structure yourStructureHandle
    – Oli
    Commented Nov 24, 2020 at 15:36
  • thx, works like a charme! Commented Nov 25, 2020 at 8:00
  • Great, I'll add it as an answer then!
    – Oli
    Commented Nov 25, 2020 at 10:12

1 Answer 1

1

Take a database backup first to be on the safe side then run:

./craft utils/repair/section-structure yourStructureHandle

See documentation - https://craftcms.com/docs/3.x/console-commands.html#utils-repair-section-structure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.