Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:53:48+00:00 2026-05-30T22:53:48+00:00

How can I use two different tables for one entity in Symfony? I have

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:53:49+00:00Added an answer on May 30, 2026 at 10:53 pm

    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.

    public static function incrementVisits($id, PropelPDO $con = null)
    {
      $con = (is_null($con)) 
             ? Propel::getConnection(self::DATABASE_NAME, Propel::CONNECTION_WRITE)
             : $con;
    
      $sql = sprintf('UPDATE %s SET %s = %s + 1 WHERE %s = %d', 
                      self::TABLE_NAME, self::VIEWS, self::VIEWS,
                      self::ARTICLE_ID, $id);
    
      $stmt = $con->prepare($sql);
      return $stmt->execute();
    }
    

    You can wrap that login in a method in Article:

    public function incrementViews(PropelPDO $con = null)
    {
      return ArticleView::incrementVisits($this->getId(), $con);
    }
    

    Then you can implement something like that in a method in Article:

    public function getViews(PropelPDO $con = null)
    {
      return $this->getArticleView($con)->getViews();
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I use two different back ends for an .net Entity Framework project? I
If you have two applications residing on the same server, can you use Server.Transfer
I have a legacy data base and a relation one-to-one between two tables. The
I have 3 tables which contain different types of data related to each other.
In SQL Server 2005, we can create similar tables in two different ways. We
Say if I have two different types of sensors: one monitors analog voltage (such
I have two tables representing two different types of imagery. I am using PostGIS
I have two different schemas in Oracle (say S1, S2) and two tables in
I have two database tables: 'MyTable' which has a standard auto-incrementing primary key integer
How can I use DATEDIFF to return the difference between two dates in years,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.