I have a User
-Entity with the very base information. The User
should be able to share more detailed data in a profile. There are different ProfileSet
s for different User
s.
In this example I try to keep it simple: ProfileSet_A
is a profile with personal information, ProfileSet_B
stores anonymous data.
A User
can only have one ProfileSet
.
Entities (Pseudocode)
// table: users
class User {
protected $id,
$email,
$username,
$password; // ...
}
// table: - none -
class ProfileSet {
protected $id,
$name; // ...
}
// table: profileset_a
class ProfileSet_A extends ProfileSet {
protected $firstname,
$lastname,
$morePrivateStuff; // ...
}
// table: profileset_b
class ProfileSet_B extends ProfileSet {
protected $anyAnonymousStuff; // ...
}
// table: user_has_profileset
class UserHasProfileSet {
protected $user, // relation to User
$profileSet; // relation to ProfileSet_A OR ProfileSet_B
}
Form, ProfileSet_A
username: [ textfield ]
email: [ textfield ]
firstname: [ textfield ]
lastname: [ textfield ]
morePrivateStuff: [ textfield ]
Form, ProfileSet_B
username: [ textfield ]
email: [ textfield ]
anyAnonymousStuff: [ textfield ]
Problems
UserHasProfileSet
should relate toUser $user
and aProfileSet
, which could be an instance ofProfileSet_A
orProfileSet_B
. I'd like to have just the field$profileSet
instead of$profileSet_A
,$profileSet_B
, ...I'd like to edit the
User
and it'sProfileSet
(A or B) within the same form.
Question
How to solve the problems in a clean way? I'm open to best-practice alternatives. Maybe I'm thinking in a wrong way.
Thanks in advance!