<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>

CC BY-SA 3.0
2014-06-26T20:51:51.840Z
Thanks, Ben - I'm getting an error from your first line: Fatal error: Call to undefined method Craft\FieldModel::model() in /the/file/..
Caroline from Aquarian
CC BY-SA 3.0
2014-06-26T20:53:28.917Z
just fixed the typo, try again
Ben Croker
CC BY-SA 3.0
2014-06-26T20:58:56.713Z
That did it! Please stay tuned for my next question - which may be the exact same for Arguement 2..
Caroline from Aquarian
CC BY-SA 3.0
2014-06-26T21:01:09.243Z
in theory it should follow the same principle as the code above...
Ben Croker
CC BY-SA 3.0
2014-06-26T21:04:24.190Z
All of this involves big structures that I've never seen before so I need more experience to grasp these patterns.
Caroline from Aquarian
CC BY-SA 3.0
2014-06-26T20:46:32.237Z
2014-06-27T16:26:10.620Z
2014-06-27T16:26:10.620Z
Ben Croker
<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>

<entrymodel><tags>
Turn a tag field id into an instance of the tag model
# 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:
$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.  

---

