How can I use two different tables for one entity in Symfony?
I have an entity calles ‘Article’ which represents a blog article.
It consists of the following properties:
- Article ID
- Title
- Author
- Text
- Date
- Views
I remember reading that a table cache is somewhat destroyed when something is written to it. That’s why I’d like to have a separate table containing only the article ID and the number of views.
You can have a table article_views with the article_id as a FK and visits counter.
You an update it “on-the-fly” with Propel and symfony 1.4 by a peer method in it’s peer class on each visit by giving the article id and connection.
You can wrap that login in a method in Article:
Then you can implement something like that in a method in Article:
Another possible solution for offline/delayed processing is to use a message queueing system and put a message there with the id of the article every visit. Then on a given interval retrieve the messages and update the table with a method similar to the one above but with variable for the new visits you would like to add.
This option will make the UPDATE queries load more predictable, but will introduce some delay.
Hope this helps. I guess the table cache you are referring is the cache for the SELECT on MySQL.