Can an Entity be available only for a session?

I would like to have an Entity that is used only durring a session. Every person using the application would have their own data in their own entity.  Once the session is over, the data in the Entity is deleted.  This would allow each user to have there own set of data.

Why not make and entity with a foreign key to Users entity.

Users entity?

In the systems Espace is the users entity.

You can get logged in user id using GetUserId() and filter and write your data on it.

That will not work for me.  I have made the game of Draw Poker and I need to keep the cards seperated from each of the users.  In other words each user has their own set of cards.  So I need an Entity per a given session.  According to what I have now read in the Forum, this cannot be done.

I don't think you understand my suggestion. Why would you not be able to store data from different users in one entity and filter on user id?

 This is very basic database concept.

Orders for different customers are stored in one orders table, same concept.

Then I would have to have a column for each user.  Who knows how many users I will have?  Currently, I mark the card as used when it has been selected, if another user comes along to pay, then they need to be able to use the same card, but if the status is used (by another player) then they cannot use the card.

I will try and find a differen t way to deal with this issue.

Sorry you don't understand me I never said you need a column per user, I wrote you need one column called userId which is s foreign key to the users table.

So given your brief description of what you try to achieve you have an entity with cards with an attribute userId. If user if is nullIdentifier() then card is available for selection. If the userId contains a valid userId it is selected.


Then two users cannot have the same card since you can only have one userid per a given card.

Curtis Muhlestein wrote:

Then two users cannot have the same card since you can only have one userid per a given card.

I base my response on your input " but if the status is used (by another player) then they cannot use the card."

All you want is possible, with a proper entity model with standard OutSystems functionallity.

Solution

If you want two users to have the same card possible too, you have a model of 3 entities:

card 

user

and cardsPerUser (which will hold CardId, UserId) and make a unique index on those two attributes.

Solution

That would be correct, if you want to go that direction.

One suggestion, for many problem domains there are reference data models, it doesn't mean you have to implement them excatly, but you can study them and use what is useful for you. Most problems have been solved before.

An example reference model for card game can be found here:

https://my.vertabelo.com/model/kNjSdbaB3ahU07FDTHImLWBMKw4ZE9Iv

More detailed information on that model can be found here:

https://www.vertabelo.com/blog/what-do-poker-blackjack-belot-and-preference-have-to-do-with-databases/

Enjoy your project!