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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Adding multiple dataobjects with many_many_extraFields to componentset


Go to End


2 Posts   1284 Views

Avatar
alexyoungs

Community Member, 5 Posts

11 December 2011 at 4:20am

Edited: 11/12/2011 4:27am

Hi all,

I'm trying to figure out the most efficient way of adding multiple dataobjects to a componentset - addMany() would work perfectly except there doesn't seem to be the option of including many_many_extraFields data along with the ID array.

Does anyone know of any way this can be done without having to loop through each dataobject and use add()? I'm looking to loop across thousands of records at a time, so efficiency is the most important factor here.

I suppose a batch insert with addMany() could be followed by some sort of batch update, if such a thing exists?

Cheers!

Avatar
alexyoungs

Community Member, 5 Posts

11 December 2011 at 6:44am

So it seems after a bit of digging through Sapphire's core, addMany() is simply a shorthand foreach add() loop, so probably won't help efficiency much.

Perhaps looping through each dataobject and building a manual SQL command to execute at the end of the loop is the simplest answer here ...