How can I do something like this in outsystems?:
Hi Jota,
There are several ways to do what you want, but the question is: why do you want it? Ids won't be unique, so there's imho no use to have a "LikableId" that's either a PhotoId or an ImageId, since it isn't unique without the type.
That said, these are some solutions:
Hi Jorge,
Real polymorphism doesn't exist in OutSystems, but you could create a Static Entity 'LikableType' with two values, 'Photo' and 'Video'. If you add a field LikableTypeId in entity Like, then you can reference one of the two values.Regards,Lennart
what I would build is on photo/video tables include one column with the value (P/V) and the same on the Like table so when fetching the photo/video with the ID and that extra column.
Other options that I thought is if it only 2 options with think using a boolean column, if its true then video else photo.
Hope it helps you.
Regards.
To complement the other two responses with some personal experience;
We have solved this in the past by simply storing the ID either as Text or Long Int. It will make joining this in an aggregate almost impossible but that was of no issue for our use case. You just need another property (that you already have) that indicates what the referenced type was so you can query the correct Entity to retrieve the data.
I do hope that they will support a gremlin based database in the future. This would make these types of references a breeze to implement :)
I find your answer interesting; However, I still don't fully understand it. Could you explain a little more please?
Hi jota,
I agree with @Kilian Hekhuis second option. We have implemented same in one of our previous project and it works absolutely fine.