I have a Media object in the application I'm working on, has associations with several other objects: Speaker , Tag , Category , etc.
In the code below, I showed the tool that I wrote to create some test data. Obviously, there is a lot of time to set up and assign numerous relationships between data.
public function load(ObjectManager $manager) { $videoType = new Mediatype(); $videoType->setName('video'); $videoType->setType('video'); $manager->persist($videoType); $speaker1 = new Speaker(); $speaker1->setName('Joe Bloggs'); $speaker1->setBiography('Joe Bloggs bio.'); $manager->persist($speaker1); $category1 = new Category(); $category1->setName('PHP'); $category1->setSlug('php'); $manager->persist($category1); $tag1 = new Tag(); $tag1->setName('PHPNW'); $tag1->setSlug('phpnw'); $manager->persist($tag1); $video1 = new Media(); $video1->setMediatype($videoType); $video1->setSpeakers( new ArrayCollection( array( $speaker1 ) ) ); $video1->setCategories( new ArrayCollection( array( $category1 ) ) ); $video1->setTags( new ArrayCollection( array( $tag1 ) ) ); $video1->setDate(new \Datetime()); $video1->setCreationDate(new \DateTime()); $video1->setTitle('My video about PHP'); $video1->setDescription('A video about PHP!'); $video1->setContent('http://some.video-url.com'); $video1->setLength('20:00:00'); $video1->setRating(2.5); $video1->setVisits(100); $video1->setLanguage('EN'); $video1->setHostName('PHP'); $video1->setHostUrl('php'); $video1->setStatus('pub'); $manager->persist($video1); $manager->flush(); }
Now I want to replace this device with real data and download about a dozen Media objects in one device. I could copy and paste it a dozen times and make changes to the data, but it's messy and harder to maintain. Is there a good way to load many objects of the same type like this?
source share