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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:17:24+00:00 2026-05-15T14:17:24+00:00

I have three tables: Project: … relations: User: local: authorId foreign: id Users: class:

  • 0

I have three tables:

Project:
  ...
  relations:
    User:
      local: authorId
      foreign: id
    Users:
      class: User
      local: projectId
      foreign: userId
      refClass: UserProjects

User:
  ...
  relations:
    Projects:
      class: Project
      local: userId
      foreign: projectId
      refClass: UserProjects

UserProjects:
  columns:
      id:
        type: integer
        primary: true
        autoincrement: true
      userId: integer
      projectId: integer

What I would like to do is write a DQL statement to return the projects that a user is associated to. I’m trying to emulate the following:

SELECT p.* 
FROM user_projects AS up
LEFT JOIN project AS p ON up.projectid = p.id
LEFT JOIN user AS u ON up.userid = u.id
WHERE u.id = 1

Reading through the Doctrine instructions I came up with the following (u.* is in there because it complained about u not being used in the select statement):

$q = Doctrine_Query::create()
  ->from('Model_User u')
  ->select('u.*, p.*')
  ->leftJoin('u.Projects p');
$result = $q->execute();

What it returns though is a data set containing a single Model_User object with a ‘Projects’ property filled in with the associated projects. I’d like to just have the projects returned if possible, but I can’t seem to figure that out. Is it possible?

  • 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-15T14:17:25+00:00Added an answer on May 15, 2026 at 2:17 pm

    I had my relationships wrong. I had to do the following and I was able to have Doctrine automatically build correct relationships without having to use DQL (So I could go $user->UserProjects or $project->UserProjects)

    Project:
      columns:
        id:
          type: integer
          primary: true
          autoincrement: true
        ...
        authorId: integer
        ...
      relations:
        User:
          local: authorId
          foreign: id
        Users:
          foreignAlias: Projects
          class: User
          refClass: UserProjects
    
    User:
      columns:
        id:
          type: integer
          primary: true
          autoincrement: true
        ...
    
    UserProjects:
      columns:
          id:
            type: integer
            primary: true
            autoincrement: true
          user_id: integer
          project_id: integer
      relations:
        Project:
          foreignAlias: UserProjects
        User:
          foreignAlias: UserProjects
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables: Employee(EmployeeID,Fname,Lname...) ProjectHeader(ProjectID,LeadID,Status....) ProjectDetails(ProjectDetailsID,ProjectID....) Here's my current code: $get_projects = SELECT
I have three tables Author, Book and AuthorBook. AuthorBook table only contains two foreign
I have three tables Prospect -- holds prospect information id name projectID Sample data
I have three tables: project (idproject, name) color (idcolor, name) project_has_color (idproject, idcolor) Now
I have say three tables. Projects Id Name Categories Id Name ProjectCategories Id ProjectId
I've ran into a design issue; in a project, i have three tables: League,
I have the following task. Having three models Project, User and PurchaseOrder. I want
I have three tables: one indexed by the names of projects (PROJECT) one indexed
I have 3 tables: Project, User and Role. Now I would like to have
I have the following scenario: project -----> company <----- clientdetails I have three tables:

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.