Hi everyone,
I'm currently on 8.4 training exercise, the one with star ratings. When I try to rate anonymously, it returns the error below (attached image). But when I rate while logged in, it is successful. May I know if what is the correct procedure here? Thank you.
Hi,
I think because of GetUserId() return Nullidentifier() when you try to rate anonymously. And in the UserMovieRating Entity UserId is mandatory so the error happened.
Cheers,
Khuong
To explain what happens what @Khuong Truong correctly describes is that because your UserId is a foreign key to the User entity and Is Mandatory is set to True, at saving the record in the database table, OutSystems will set the value of UserId to 0 because you did not provide a value. But in the User entity there is no record with Id = 0. That is causing the exception to be thrown.
If you set Mandatory to False, then when UserId is NullIdentifier() the record will be saved with value NULL in the database.
All of this is only relevant for foreignkey attributes.
Thank you very much, @Khuong Truong and @Daniël Kuhlmann !
Hi @Daniël Kuhlmann,
Thanks for your detail explanation, just a small point (maybe typo) that is default UserId is 0 not 9.
Regards,
You are welcome Miguel !!!
typo fixed