craftcms / feed-me

Craft CMS plugin for importing entry data from XML, RSS or ATOM feeds—routine task or on-demand.
Other
288 stars 139 forks source link

Unknown column when parent data provided is field #1422

Closed mortenta closed 5 months ago

mortenta commented 6 months ago

Description

Running in JSON import to a structure section, and to maintain the structure I've added two fields; origId and origParentId, where origId represents a unique id of each entry and the origParentId is the id of the parent entry.

The JSON records has two corresponding fields that is imported, and the order of the records in the JSON is such that all parents are imported before their children.

When run, nothing gets imported, and the log reveals that column origId is not found:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'origId' in 'where clause' The SQL being executed was: SELECT elements.id, elements.canonicalId, elements.fieldLayoutId, elements.uid, elements.enabled, elements.archived, elements.dateLastMerged, elements.dateCreated, elements.dateUpdated, elements_sites.id AS siteSettingsId, elements_sites.siteId, elements_sites.title, elements_sites.slug, elements_sites.uri, elements_sites.content, elements_sites.enabled AS enabledForSite, entries.sectionId, entries.fieldId, entries.primaryOwnerId, entries.typeId, entries.postDate, entries.expiryDate, structureelements.root, structureelements.lft, structureelements.rgt, structureelements.level FROM (SELECT elements.id AS elementsId, elements_sites.id AS siteSettingsId FROM elements elements INNER JOIN entries entries ON entries.id = elements.id INNER JOIN elements_sites elements_sites ON elements_sites.elementId = elements.id LEFT JOIN structureelements structureelements ON (structureelements.elementId = elements.id) AND (structureelements.structureId=1) WHERE (entries.sectionId=3) AND (origId = 'getting_started-tutorials-') AND (elements.archived=FALSE) AND (elements.dateDeleted IS NULL) AND (elements.draftId IS NULL) AND (elements.revisionId IS NULL) ORDER BY structureelements.lft, entries.postDate DESC, elements.id DESC LIMIT 1) subquery INNER JOIN elements elements ON elements.id = subquery.elementsId INNER JOIN elements_sites elements_sites ON elements_sites.id = subquery.siteSettingsId INNER JOIN entries entries ON entries.id = subquery.elementsId LEFT JOIN structureelements structureelements ON (structureelements.elementId = subquery.elementsId) AND (structureelements.structureId=1) ORDER BY structureelements.lft, entries.postDate DESC, elements.id DESC - Schema.php: 676.

I assume this is due to the db schema change from Craft CMS 4 to Craft CMS 5, where the field names has been moved inside elements_sites.content as JSON with reference to fields (?)

Steps to reproduce

  1. Import a JSON array e.g. [{"name":"Parent A","origId":"parent-a","parentId":""},{"name":"Child A","origId":"child-a","parentId":"parent-a"}]
  2. Create structure section, with fields name, origId, parentId, all text.
  3. Create a Feed Me import, import the content fields, and select parentId under Entry fields > Parent, and "Data for this entry is: [origId]".

Additional info

i-just commented 5 months ago

Hi, thanks for reporting! I can’t replicate this error with the latest Craft (5.1.0) and Feed Me (6.0.1) versions, but I can see that there is an issue with matching a parent based on a custom field. I’m working on a solution for that one.

i-just commented 5 months ago

I'm actually able to reproduce it today (I chose an unfortunate field name yesterday). I'm working on a fix.

mortenta commented 5 months ago

Awesome, looking forward to the fix 👍