Reputation: 1246
I am using zf2 and Doctrine for a project I am developing, and I need to create a function that takes all of the records from a SELECT
query and inserts or appends them into another table (or entity). The Doctrine documentation says that QueryBuilder only offers SELECT
, DELETE
and UPDATE
functionality, and I remember reading somewhere that INSERT
and APPEND
are not included because Doctrine doesn't want to lose control of related records that might go missing by only updating one table that has relationships with others.
How can I use Doctrine to add a group of records to a table?
Upvotes: 0
Views: 1360
Reputation: 3408
You can create enities from records and push them to db:
foreach ( $records as $record ) {
$someEntity = new SomeTable();
$someEntity->setName($record['name']);
$someEntity->setFoo($record['bar']);
$em->persist($someEntity);
}
$em->flush();
Upvotes: 2