<p>If I'm understanding you correctly, what you're looking for is the <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/RelationsService.php#L29" rel="nofollow">RelationsService's saveRelations()</a> accessed via <code>craft()-&gt;relations-&gt;saveRelations()</code>.</p>

<p>You pass in your $fieldModel, $source ElementModel and an array of $targetIds that you want to created the relations to.</p>

CC BY-SA 3.0
2014-11-28T08:12:54.077Z
Brad thanks for your reply. The solution given by you is for more relations, i only need one relation insertion.
Gerritjan
CC BY-SA 3.0
2014-11-27T17:26:17.897Z
2014-11-27T17:26:17.897Z
Brad Bell
<p>this is my first question on StackExchange regarding CraftCMS. </p>

<p>Currently im working on a plugin that should insert a relation row (in db) regarding an entry and asset (image). </p>

<p>Is there a simple and easy way to insert a row in the DB with asset id, source id and field id?</p>

<p>Thanks in advance</p>

CC BY-SA 3.0
2014-11-27T20:16:13.040Z
I'm a co-worker of Gerritjan and I will try to explain the question some more. We have a channel projects and a channel ideas. A project has related ideas through a field of the type entry. On the front-end our visitors can suggest ideas through a form for that project.
An idea is a title, image and description. How can we save this form easily in Craft when submitted?
Tom Suter
CC BY-SA 3.0
2014-11-28T16:35:33.990Z
If you're looking for a form-building solution, check out http://straightupcraft.com/craft-plugins/sprout-forms
Brad Bell
<plugin-development><database>
Relation row insertion in DB (plugin)
# Relation row insertion in DB (plugin)

(Asked by: username_0 on 2014-11-27)

this is my first question on StackExchange regarding CraftCMS.

Currently im working on a plugin that should insert a relation row (in db) regarding an entry and asset (image).

Is there a simple and easy way to insert a row in the DB with asset id, source id and field id?

Thanks in advance

**Tags:** plugin-development, database

> **Comments:**
> **username_1**: I'm a co-worker of username_0 and I will try to explain the question some more. We have a channel projects and a channel ideas. A project has related ideas through a field of the type entry. On the front-end our visitors can suggest ideas through a form for that project. An idea is a title, image and description. How can we save this form easily in Craft when submitted?  
> **username_2**: If you're looking for a form-building solution, check out http://straightupcraft.com/craft-plugins/sprout-forms  

---

## 1 answers

### Answer by username_2 on 2014-11-27. Score: 2

If I'm understanding you correctly, what you're looking for is the [RelationsService's saveRelations()](https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/RelationsService.php#L29) accessed via `craft()->relations->saveRelations()`.

You pass in your $fieldModel, $source ElementModel and an array of $targetIds that you want to created the relations to.

> **Comments:**
> **username_0**: Brad thanks for your reply. The solution given by you is for more relations, i only need one relation insertion.  

---

