Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

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

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

batch add to relationtable without $form->saveInto...


Reply


6 Posts   1884 Views

Avatar
dio5

Community Member, 501 Posts

27 November 2007 at 10:02am

How can I fill the Tip_Tags table when I'm not using $form->saveInto(); ?

If you take a look at my code http://pastie.caboo.se/122204 around line 29 I'm doing it all wrong...

I'm wanting to 'batch' fill the tags table and fill the relationship table at once.
The tags part is easy...

Avatar
dio5

Community Member, 501 Posts

27 November 2007 at 10:35am

Solved.

   $Tip->Tags()->add($savedTag);
   $Tip->write();

Easy, but you gotta know it. :-)

Avatar
Sean

Forum Moderator, 922 Posts

27 November 2007 at 11:57am

The output of Tags() is a ComponentSet I assume?

Sean

Avatar
dio5

Community Member, 501 Posts

27 November 2007 at 12:14pm

I guess so.. they're in a many_many relation, but somehow I missed out that you could do
$Tips->Tags()->add();

Avatar
Sean

Forum Moderator, 922 Posts

27 November 2007 at 12:18pm

Yeah, that's definitely a ComponentSet then.

If you have relationships like has_many many_many etc, then the results return a ComponentSet which is a sub-class of DataObjectSet (exactly the same as a DataObject::get() call, but with extra relationship features).

The great thing is you can also use remove(), getIdList(), addMany(), removeMany() or any other useful methods in ComponentSet for managing the relationship.

Cheers,
Sean

Avatar
dio5

Community Member, 501 Posts

27 November 2007 at 11:38pm

Thanks, that's great!