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 7744515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:47:11+00:00 2026-06-01T09:47:11+00:00

I have two tables in my database: user and media_contact . The media_contact table

  • 0

I have two tables in my database: user and media_contact. The media_contact table has a user_id, so, obviously, my intent is to be able to select media contacts based on a user.

The problem I’m having is that this fails:

// VNN/PressboxBundle/Entity/User.php
// $this in this case is a User object with id 26
$customContacts = $em->getRepository('VNNPressboxBundle:MediaContact')->findByUser($this);

This gives me nothing. $customContacts is empty. But:

mysql> select * from media_contact where user_id=26;
+-----+-------------+-----------------------+---------------+---------+
| id  | name        | email                 | media_area_id | user_id |
+-----+-------------+-----------------------+---------------+---------+
| 177 | Jason Swett | jason.swett@gmail.com |          NULL |      26 |
| 183 | Sam         | sam@sam.com           |          NULL |      26 |
+-----+-------------+-----------------------+---------------+---------+
2 rows in set (0.00 sec)

It should really be returning two objects. I really don’t understand why this is happening.

Here are my annotations:

// User.php

/** 
 * @ORM\OneToMany(targetEntity="MediaContact", mappedBy="user")
 */
private $mediaContacts;

–

// MediaContact.php
/** 
 * @ORM\ManyToOne(targetEntity="User", inversedBy="mediaContacts")
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 */
private $user;

What could be going wrong?

  • 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-06-01T09:47:12+00:00Added an answer on June 1, 2026 at 9:47 am

    You have to use $this->getId() instead of $this in order for it to work:

    $customContacts = $em->getRepository('VNNPressboxBundle:MediaContact')->findByUser($this->getId());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one database that has two tables. One table (Table A) has 3
I have two tables. The first table holds simple user data and has the
Imagine we have two tables in the database, user (FK id_role) and role (PK
i have two tables in my database : Users : contain user information UserTypes
I have two tables in my database USERS, and USER_SESSIONS. USER_SESSIONS has a foreign
I have two tables in my access database that I want to be able
I have two tables users registered_members I want to confirm values from user table
I have two tables from two different databases. For example: Table: Articles1 - Database:
I have two tables in my database that look like this CREATE TABLE IF
I have two tables in database: comments table users table | u_id | text

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.