Hello kind helper folk,

I'm working with Simple Craft XML Import, which has a handful of older code in it. I've managed to get through most of it to the very end.

The last thing it does is saves tags. My tags are saved, but now it has to relate it back to the entry and Craft appears to be saving them but not relating them back correctly, and not throwing an error.

The saveRelations function appears to need:

an instance of Craft\FieldModel provided in arg 1

an instance of Craft\BaseElementModel provided in arg 2

.. the data in arg 3.

I have the following code:

                $tagFieldRecord = FieldRecord::model()->findByPk($tagFieldId);

                $tagFieldModel = FieldModel::populateModel($tagFieldRecord);

                $entryRecord = EntryRecord::model()->findById($entryRecord['elementId']);

                $entryModel = EntryModel::populateModel($entryRecord);

                craft()->relations->saveRelations($tagFieldModel, $entryModel, $tags);

Everything appears to have saved in the db tables - tags and the relations, but when I go to the entries in the back end, there are no tags.

Is there a good db value to look in on and change to get these to work?

Also, is there something in my code I can change to make this happen through the code and not hacking the db?

  • Did you set these settings?
    – Natetronn
    Jun 27 '14 at 16:34
  • Good question!! Yes I set all the settings. Everything imported as desired/expected - but the relationship of the tags to the entries does not appear to have saved when I go to look at the entries in the CP. There was no error code at all. Jun 27 '14 at 16:39
  • I re-examined them and they were wrong. Ugh I feel like such an idiot. Thank you! Jun 27 '14 at 16:45
  • 1
    @Natetronn, post that as a real answer so Petroglyph can declare you the winner and you can get your much deserved points. :)
    – Lindsey D
    Jun 27 '14 at 16:49

Please make sure the tag settings in CraftImportService.php are set properly.

  • D'OH!!! This was one of the first things I tried to do with almost zero frame of reference. Of course I'd mess this up. Thanks Nate! Jun 27 '14 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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