Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-28T08:12:54.077Z
Answers.Text: Brad thanks for your reply. The solution given by you is for more relations, i only need one relation insertion.
Answers.UserDisplayName: Gerritjan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-27T17:26:17.897Z
Answers.LastActivityDate: 2014-11-27T17:26:17.897Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-27T20:16:13.040Z
Comments.Text: 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?
Comments.UserDisplayName: Tom Suter
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-28T16:35:33.990Z
Comments.Text: If you're looking for a form-building solution, check out http://straightupcraft.com/craft-plugins/sprout-forms
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><database>
Title: Relation row insertion in DB (plugin)
ThreadText: # 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**: username_2 thanks for your reply. The solution given by you is for more relations, i only need one relation insertion.  
  
  ---
  
  