getUsers() as $user) { $profileId = $user->createDefaultProfile($this->_view); foreach ($fieldsValues->getForUser($user) as $fieldValue) { $fieldValue->profile_id = $profileId; $fieldValue->save(); } } $this->_db->query('ALTER TABLE `fields_values` ADD FOREIGN KEY ( `profile_id` ) REFERENCES `profiles` (`id`) ON DELETE CASCADE'); } }