Any way to validate a condition from a read actions instead of policies or filters?
So, normally I use filters modules when I want to validate something in read actions (ex. if I want to filter classes of a school (both resources), I pass the school_id and also filter it by checking if the actor is also from that same school.
That kind of filter works great for most of the cases, but sometimes I just want to actually check some validation and return an error (or empty list if the error is not possible) without having the add that validation directly in the resulting SQL query.
Normally, specially if the validation is more complex, I create a change module that does the validation and return an error if it didn't pass. But I can't use a change module in a read action.
I believe I could achieve that by creating policies, but from other discussions here, my understanding is that policies should be for simple things directly related to the actor struct, not something that is more complex and will query the database for more data.
I also took a look into the Preparation behavior, but that one always return a query, so I can't see how I would actually return an error instead.
So, in this case, what is the best approach you would suggest @Zach Daniel ?
That kind of filter works great for most of the cases, but sometimes I just want to actually check some validation and return an error (or empty list if the error is not possible) without having the add that validation directly in the resulting SQL query.
Normally, specially if the validation is more complex, I create a change module that does the validation and return an error if it didn't pass. But I can't use a change module in a read action.
I believe I could achieve that by creating policies, but from other discussions here, my understanding is that policies should be for simple things directly related to the actor struct, not something that is more complex and will query the database for more data.
I also took a look into the Preparation behavior, but that one always return a query, so I can't see how I would actually return an error instead.
So, in this case, what is the best approach you would suggest @Zach Daniel ?
