What is the best practices for computed properties?
Hi!
Let's say you have a "Course" with many "Lessons". Each Lesson has like "Exercise" that could be "Success" or "Failed".
You want to display a "Completed" badge on the course of the students.
However, to have the "Completed" badge, you must check that each "Lesson" and each "Exercise" has been completed.
You could make the calculation each time using a custom attribute or save it in the database and update it when needed.
https://nox.tips/
What is the best practice? Getting it each time seems costly and saving it in the database seems unreliable...
And this is not a real "problem" I have, I just used random models so you can get an idea of the discussion I am trying to have.
Personally, I would definitely store the state in the database. As you said yourself; it's simply too costly calculating this run-time.
In the given scenario, I see no issues with it being "unreliable" storing this in the database.
I'd love to hear your reasoning for thinking that approach would be unreliable.