17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1696 Views |
-
batch add to relationtable without $form->saveInto...

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... -
Re: batch add to relationtable without $form->saveInto...

27 November 2007 at 10:35am
Solved.
$Tip->Tags()->add($savedTag);
$Tip->write();Easy, but you gotta know it.
-
Re: batch add to relationtable without $form->saveInto...

27 November 2007 at 11:57am
The output of Tags() is a ComponentSet I assume?
Sean
-
Re: batch add to relationtable without $form->saveInto...

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(); -
Re: batch add to relationtable without $form->saveInto...

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 -
Re: batch add to relationtable without $form->saveInto...

27 November 2007 at 11:38pm
Thanks, that's great!
| 1696 Views | ||
|
Page:
1
|
Go to Top |


