2

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

2
  • 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
    Nov 27, 2014 at 20:16
  • 1
    If you're looking for a form-building solution, check out straightupcraft.com/craft-plugins/sprout-forms
    – Brad Bell
    Nov 28, 2014 at 16:35

1 Answer 1

2

If I'm understanding you correctly, what you're looking for is the RelationsService's saveRelations() 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.

1
  • Brad thanks for your reply. The solution given by you is for more relations, i only need one relation insertion.
    – Gerritjan
    Nov 28, 2014 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.