2

The add-on I'm using to import blogs has this to save tags to an entry:

craft()->relations->saveRelations($tagFieldId, $entryRecord['elementId'], $tags);

Where the first arg is the field id for the tag, the second is the entry, and the third is the tags.

I'm getting an error that says $tagFieldId needs to be an instance of the tag model:

Argument 1 passed to Craft\RelationsService::saveRelations() must be an instance of Craft\FieldModel,

Can I turn my little field ID into an instance of this? How do I get a fresh one, if not? Thanks for your help.

Any suggestions on approaches appreciated.

Also - would tag tagmodel but I'm a wee newbie.

2

You need to get the FieldModel using the $tagFieldId variable, and then pass that model into the function as follows:

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

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

craft()->relations->saveRelations($tagFieldModel, $entryRecord['elementId'], $tags);
  • Thanks, Ben - I'm getting an error from your first line: Fatal error: Call to undefined method Craft\FieldModel::model() in /the/file/.. – Petroglyph Creative Jun 26 '14 at 20:51
  • just fixed the typo, try again – Ben Croker Jun 26 '14 at 20:53
  • That did it! Please stay tuned for my next question - which may be the exact same for Arguement 2.. – Petroglyph Creative Jun 26 '14 at 20:58
  • in theory it should follow the same principle as the code above... – Ben Croker Jun 26 '14 at 21:01
  • All of this involves big structures that I've never seen before so I need more experience to grasp these patterns. – Petroglyph Creative Jun 26 '14 at 21:04

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.