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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:32:23+00:00 2026-05-26T11:32:23+00:00

On my mysql db, I have two tables: User And UserProfile. The table UserProfile

  • 0

On my mysql db, I have two tables: “User” And “UserProfile”. The table “UserProfile” has a foreign key column named ‘user_id’ which links to “User” table’s “id” column. Now, when I am generating all entity classes from my db tables using doctrine, the created “UserProfile” class contains a property named ‘user'(which is of “User” type) and doesn’t contain any property named ‘user_id’. Is it ok?

Now, if I want to find a user’s profile, given the user_id, I needed to write something like this:

$user_profile_repo = $this->em->getRepository("UserProfile");

$user_profile = $user_profile_repo->findOneBy(array("user_id"=>$id));

But as the generated entity class doesn’t include the “user_id” property, the above code won’t work. Now I need to know how can I do the tweak to make the above code work please? Thanks.

  • 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-26T11:32:23+00:00Added an answer on May 26, 2026 at 11:32 am

    the actual names of the tables/columns in the database are not really important. you can set them in the comments.

    it should be something like this:

    /**
     * models\User
     * @Table(name="User")
     * @Entity
     */
    class User
    {
        /**
         * @Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
         * @Id
         * @GeneratedValue(strategy="IDENTITY")
         */
        private $id;
    
        /**
         * @Column(name="name", type="string", length=50, precision=0, scale=0, nullable=false, unique=false)
         */
        private $name;
    
        /**
         * @OneToOne(targetEntity="models\UserProfile", mappedBy="user")
         */
        private $profile;
    }
    
    
    /**
     * models\UserProfile
     * @Table(name="UserProfile")
     * @Entity
     */
    class UserProfile
    {
        /**
         * @OneToOne(targetEntity="models\User", inversedBy("profile"))
         * @JoinColumn(name="user_id", referencedColumnName="id")
         */
        private $user;
    }
    

    in this case a user has the column id, and the userprofile has user_id

    once generated, you should get in the User the method getProfile() and in the UserProfile you should get getUser()

    it is similar to 5.7 oneToOne bidirectional: http://www.doctrine-project.org/docs/orm/2.0/en/reference/association-mapping.html

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

Sidebar

Related Questions

I have two tables on mysql: users, and management. The users table has a
I have two MySQL tables: User (with an auto-incremented pk id) and WaitingUser which
using php and mysql I have two tables, a users table and a profiles
I have two mysql tables: USER and ROSTER. Previously, I've been able to query
I have a simple mySQL problem-- I have two tables, one is a user's
I have two MySQL tables: Group(gr_id, gr_name, gr_description, parent_id) Group_has_User(User_id, Group_id) I'm trying to
Say I have two tables, users and groups each of which has an auto-incrementing
I have two tables, one user_info : table user_info { user_id ; fname; laname;
I have two MySQL tables like this: User Id (PK, auto-increment integer) Subscriber Id
I have two mysql tables: /* Table users */ CREATE TABLE IF NOT EXISTS

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.