Does the new User model share the same UserData and OtherData models with the old User model?
I mean, is the following correct?
Old users and their data:
an OldUser has many UserData
a UserData has many OtherData
New users and their data:
a NewUser has many UserData
a UserData has many OtherData
If this is the case, then a newly created NewUser may already have some UserData without intentionally creating new UserDatas. They are originally created for an OldUser and have its id as their user_id, but when a NewUser has the same id, they will be treated as the child records of it.
So I think the following will work if the NewUser has the same UserData and OtherData with the OldUser:
$oldUsers = OldUser::findAll();
foreach ($oldUsers as $oldUser) {
$newUser = new User();
$newUser->id = $oldUser->id;
// some attributes
$newUser->save();
}
There’s no need to loop through the UserDatas and OtherDatas.
Hi, I’m really sorry it was complete my fault.
I had in the model classes of UserData and OtherData an afterSave function… I comment my code out and now it works fine XD. Sorry