Tell a user whether they have already viewed an item in a list. How?

Posted by user2738308 on Programmers See other posts from Programmers or by user2738308
Published on 2013-11-04T03:08:58Z Indexed on 2013/11/04 4:12 UTC
Read the original article Hit count: 194

Filed under:
|

It is pretty common for a web application to display a list of items and for each item in the list to indicate to the current user whether they have already viewed the associated item.

An approach that I have taken in the past is to store HasViewed objects that contain the Id of a viewed item and the Id of the User who has viewed that item.

When it comes time to display a list of items this requires querying for the items, and separately querying for the HasViewed objects, and then combining the results into a set of objects constructed solely for the purpose of displaying them in the view.

Each e.g li then uses the e.g. has_viewed property of the objects constructed above.

I would like to know whether others take a different approach and can recommend alternative ways to achieve this functionality.

© Programmers or respective owner

Related posts about web-applications

Related posts about mvc