MySQL, . , user_id.
, .
- ? , : ? - , ? : RegisteredUser UnknownPosterWithEmailAddress, ?
NULLable user_id NULLable , , , " , , ", , :
select post.id,
case when post.user_id is not null then user.email
else post.email end as email
from post
left join user on user.id=post.user_id;
.
: User dsitinct , NULLable, :
create table user(id integer primary key,
email text not null unique,
is_registered boolean default false);
create table post(id integer primary key,
user_id integer not null references user(id),
content text);
, user.id, . , : , ? , NULLable.
, , ( user.id , , is_registered ). :
- If he sent it to the same email address, now all his old messages are automatically associated with his new registered identifier.
- If a user changes his email address in his profile, all replies to older messages will be "seen" by his new updated email address.
source
share