Answers.Body: <p>You need to get the FieldModel using the <code>$tagFieldId</code> variable, and then pass that model into the function as follows:</p>
  
  <pre class="lang-php prettyprint-override"><code>$tagFieldRecord = FieldRecord::model()-&gt;findById($tagFieldId);
  
  $tagFieldModel = FieldModel::populateModel($tagFieldRecord);
  
  craft()-&gt;relations-&gt;saveRelations($tagFieldModel, $entryRecord['elementId'], $tags);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T20:51:51.840Z
Answers.Text: Thanks, Ben - I'm getting an error from your first line: Fatal error: Call to undefined method Craft\FieldModel::model() in /the/file/..
Answers.UserDisplayName: Caroline from Aquarian
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T20:53:28.917Z
Answers.Text: just fixed the typo, try again
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T20:58:56.713Z
Answers.Text: That did it! Please stay tuned for my next question - which may be the exact same for Arguement 2..
Answers.UserDisplayName: Caroline from Aquarian
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T21:01:09.243Z
Answers.Text: in theory it should follow the same principle as the code above...
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T21:04:24.190Z
Answers.Text: All of this involves big structures that I've never seen before so I need more experience to grasp these patterns.
Answers.UserDisplayName: Caroline from Aquarian
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-26T20:46:32.237Z
Answers.LastActivityDate: 2014-06-27T16:26:10.620Z
Answers.LastEditDate: 2014-06-27T16:26:10.620Z
Answers.UserDisplayName: Ben Croker
Body: <p>The add-on I'm using to import blogs has this to save tags to an entry:</p>
  
  <p><code>craft()-&gt;relations-&gt;saveRelations($tagFieldId, $entryRecord['elementId'], $tags);</code></p>
  
  <p>Where the first arg is the field id for the tag, the second is the entry, and the third is the tags.</p>
  
  <p>I'm getting an error that says $tagFieldId needs to be an instance of the tag model:</p>
  
  <blockquote>
    <p>Argument 1 passed to Craft\RelationsService::saveRelations() must be
    an instance of Craft\FieldModel,</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>Any suggestions on approaches appreciated.</p>
  
  <p>Also - would tag tagmodel but I'm a wee newbie.</p>
  
Tags: <entrymodel><tags>
Title: Turn a tag field id into an instance of the tag model
ThreadText: # Turn a tag field id into an instance of the tag model
  
  (Asked by: username_0 on 2014-06-26)
  
  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.
  
  **Tags:** entrymodel, tags
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-26. Score: 2 | Accepted answer
  
  You need to get the FieldModel using the `$tagFieldId` variable, and then pass that model into the function as follows:
  
  ```php
  $tagFieldRecord = FieldRecord::model()->findById($tagFieldId);
  
  $tagFieldModel = FieldModel::populateModel($tagFieldRecord);
  
  craft()->relations->saveRelations($tagFieldModel, $entryRecord['elementId'], $tags);
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks, Ben - I'm getting an error from your first line: Fatal error: Call to undefined method Craft\FieldModel::model() in /the/file/..  
  > **username_1**: just fixed the typo, try again  
  > **username_0**: That did it! Please stay tuned for my next question - which may be the exact same for Arguement 2..  
  > **username_1**: in theory it should follow the same principle as the code above...  
  > **username_0**: All of this involves big structures that I've never seen before so I need more experience to grasp these patterns.  
  
  ---
  
  