Let’s say I have an app that handles a TODO list. The list has finished and unfinished items. Now I want to add two virtual attributes to the list object; the count of finished and unfinished items in the list. I also need these to be displayed in the json output.
Hi!
Let's say I have an app that handles a TODO list. The list has finished and
unfinished items. Now I want to add two virtual attributes to the list
object; the count of finished and unfinished items in the list. I also need
these to be displayed in the json output.
How do I achieve that?
Define two scopes on List that return the finished and unfinished items then use
List.unfinished.count
When displaying a List as JSON I want it to have an attribute that counts how many finished items there are in the list and how many unfinished items there are in the list. The above methods only fetches the items, and I’d have to count the result of that of course.
What has that got to do with the subject of this thread, which is Add
virtual attribute? It is best to start a new thread for a new
subject, with a subject line that matches the question.