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

  • Home
  • SEARCH
  • 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 6670137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:13:59+00:00 2026-05-26T03:13:59+00:00

I am trying to model a simple comment system with 2 entities – User

  • 0

I am trying to model a simple comment system with 2 entities – User and Post. The User class has the regular properties, and the Post class looks like this:

class Post
{
/**
 * @var integer $id
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * User who posted activity
 *
 * @var User
 * @ORM\ManyToOne(targetEntity="Acme\AppBundle\Entity\User")
 */
protected $user;

/**
 * @var string $text
 *
 * @ORM\Column(name="text", type="string", length=255)
 */
private $text;

/**
 * @var datetime $timestamp
 *
 * @ORM\Column(name="timestamp", type="datetime")
 */
private $timestamp;
}

I need to make a simple association – Users can favourite posts. The logical thing to do would be to add ManyToMany association in User class to Post like so

@ORM\ManyToMany(targetEntity="Post")

Which would then create a mapping table with user_id and post_id as primary keys. Now my problem is that I need to add a timestamp property to track when the user liked a post. One possibility is to create a new Entity “FavouritePost”, map it to both User and Post class using ManyToOne association, and add a timestamp property to it.

1) Is this the right/only way to do it in Symfony2?
2) If I want to select the most recent 15 posts, and check if the currently logged in user has liked the posts, how can I write a query for that?

Any help appreciated, as I am drawing a blank on how to do it via Symfony

  • 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-26T03:13:59+00:00Added an answer on May 26, 2026 at 3:13 am

    1) Yes you may create a jointure table, and so its FavouritePost entity.

    2) You should use a Repository to create all special queries :

    @ORM\Entity(repositoryClass=”Acme\AppBundle\Repository\FavouritePostRepository”)

    Then it’s easy Doctrine queries, like you will make much more.

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

Sidebar

Related Questions

I'm trying to model this inheritance for a simple blog system Blog has many
Am trying to construct a simple update query in my model class Model_DbTable_Account extends
I've got a simple model class like so (complete with constructor of course) @implementation
I'm trying to model a simple ledger in Django and would like to clear
I am trying to model a very simple system, but the Rails way of
My application has a very simple model right now and I'm trying to find
Relatively new to rails and trying to model a very simple family tree with
I am trying to adapt a simple WPF application to use the Model-View-ViewModel pattern.
I'm trying to model class and sections of a class and further instances of
I am trying to do a simple test for my model Course , I

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.