Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Forms, objects and how to write to many_many relations

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 2229 Views
  • dio5
    Avatar
    Community Member
    501 Posts

    Forms, objects and how to write to many_many relations Link to this post

    Along with my problem
    http://www.silverstripe.com/silverstripe-development/flat/5780

    I'm having another probably stupid issue.

    How do I write to a table that is in a many_many relationship with the main object I'm writing to?
    So suppose I have in my form-processing function:

    $tip = new Tip();
    $tip->props = $data['props']
    ...

    In one of my forms I have a checkboxset with the name of Categories[].
    My class Tip can have multiple categories, so in Tip I have:

    static $many_many = array(
          'Categories' => 'Category',
       );

    Now in the formprocessing function I can access the category-array

    foreach($data['Categories'] as $cat)
    {
       $tip->Category = $cat;// this is probably wrong!!!!!
    }

    But how do I set this? This should write to tip_categories table, but obviously setting $tip->Category is not the way to do it...

    ?

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Forms, objects and how to write to many_many relations Link to this post

    Issue seems to be solved automatically when I use

    form->saveInto();

    However, none of the Longitude/latitude data from the Mapping module seems to be saved then...

    what seems logical...

    2229 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.