Check if element is in list

I have three entities that are relevant to this question: Seat, Floor and Reservation.

Every floor can contain multiple seats. Additionally, there can be MULTIPLE reservations for a seat, but only ONE reservation for a specific date.

I need to get all the seats on a certain floor that are NOT reserved for a specific date.

Originally, I was going to do this with a filter in the aggregate (I filtered Seats with or without a Reservation where:

Reservation.Id=NullIdentifier() 

and

Seat.FloorId = FloorId

The problem arises when I try to throw the dates in the mix. I only need the seats that aren't reserved for a specific date. This date I'm only getting the seats that aren't reserved ever. I've thought a lot about how to fix this issue using aggregates, but I think it would be so much simpler if I could have one aggregate that contains all the seats and one aggregate that contains all the reserved seats for a day. For each element of the list with all seats, if the list of reserved seats contains the seat, I'll skip it. Is there a "contains" action when it comes to lists? Is there any other way to fix this issue? Thank you so much in advance.

Hi Jana,

As suggested in above comment kindly try with advance query . Below is the advance query that can work in your scenario.

It will return only the available seats of a particular date .

Best Regards

Devendra


mvp_badge
MVP

Hello Jana,

There are some actions that you may be able to use to help with this:

Both of them reside in the System section of the references. ListFilter will return elements of a List that match a specific condition, and ListIndexOf will return the first position of an element inside a List that matches a condition.

However, using these sorts of actions after receiving data from the database is usually a sign that you can improve your starting query - in most cases, you can rewrite a database query to do this sort of filtering for you.

If I understood your explanation correctly, you want to exclude a seat if the list of reserved seats already contains it. You could write an EXISTS condition in your WHERE clause, but this would imply converting your aggregate to an Advanced Query.

Hi Jana,

As suggested in above comment kindly try with advance query . Below is the advance query that can work in your scenario.

It will return only the available seats of a particular date .

Best Regards

Devendra


Hi Jana,

this is possible with an aggregate by putting your condition for reservation date as a join condition, not a filter condition.

Basically, with your join condition you are first doing a withOrWithout join from seat to only reservations of your desired date, giving you a result of each seat on all floors, either with a reservation for that day or no reservation (reservation empty)

After that, you reduce the result set of the join by filtering on reservation.id being nullIdentifier and on the desired floor.

Dorine

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.