Is there a method with xPDO to do a bulk insert? example:
$genres = array('A Capella','Acid','Acoustic','African-American','Afro','Afro Beat','Alternative','Ambient','Americana',******several hundred genres****'Tropicalisimo','Turkish','Urban','None of the above');
foreach ($genres as $genre) {
$addgenre = $modx->newObject('ArtistGenres');
$addgenre->fromArray(array(
'genre' => $genre,
));
$addgenre->save();
}
A better way than just looping over the genre array?
-thanks
-sean
An afterthought - how can I reset the primary key's index via xPDO? normally I would something like:
alter table foo AUTO_INCREMENT = 1
[ed. note: sean69 last edited this post 14 years, 6 months ago.]
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
Hmmmm looking at your example [cool - thanks, BTW!] something like this should work?
<?php
$modx->exec("insert into {$modx->getTableName('ArtistGenres')} ('genre') values ('A Capella'),('Acid'),('Acoustic'),('African-American').. etc... ");
or:
<?php
$modx->exec("LOAD DATA INFILE '/tmp/data/genres.dat' into table {$modx->getTableName('ArtistGenres')}");
??
-sean
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
-
MODX Staff
- 10,725 Posts
They should as long as they are a single SQL statement, not multiple separated via a semi-colon.