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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:50:01+00:00 2026-05-13T13:50:01+00:00

I am developing a web application with PHP and MySQL. I have an entity

  • 0

I am developing a web application with PHP and MySQL. I have an entity named, User, that has many one-to-many relationships (with other objects) within it (list of Addresses, list of Emails, list of PhoneNumbers, etc). These many addresses, emails, phone numbers are supplied to the user via junction tables in the database (user_link_addresses, user_link_emails, etc).

I am now trying to create an efficient DAO for the User entity, specifically methods readUserById($userId) and readAllUsers(). However, since I am an amateur at sql and the DAO pattern, I am having trouble creating this DAO correctly.

I have been told that it is important for network efficiency to keep your DAO to one query that reads all the information at once and then can be mapped to that entity accordingly. That does make sense, but I am having trouble generating one query that has the necessary information from everything and that can be mapped correctly to my entity.

Right now, I can get this information by performing multiple queries within a loop after getting the users… I just don’t like that idea (and I’m sure it’s not correct). Also, I know how to do joins with junction tables – just not with something this complex and that needs to be mapped correctly as well.

TABLE NAMES AND FIELDS

TABLE: user
FIELDS: user_id, username, password

TABLE: address
FIELDS: address_id, street, city, state, zip_code, type

TABLE: email
FIELDS: email_id, email, type

TABLE: phone_number
FIELDS: phone_number_id, area_code, phone_number, type

— JUNCTION TABLES FOR ASSOCIATIONS —

TABLE: user_link_address
FIELDS: user_id, address_id

TABLE: user_link_email
FIELDS: user_id, email_id

TABLE: user_link_phone_number
FIELDS: user_id, phone_number_id

Anyway, all help is greatly appreciated,

Steve

  • 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-13T13:50:02+00:00Added an answer on May 13, 2026 at 1:50 pm

    Sometimes it’s worth it to include associations within queries and sometimes it’s not. There’s a really neat plugin for Ruby on Rails that analyzes your application as it runs and tells you which queries should include associated models.

    You could try something like:

    SELECT *
        FROM `user` 
        INNER JOIN `user_link_addresses`
            ON `user`.id = `user_link_addresses`.user_id
        INNER JOIN `user_link_foo`
            ON `user`.id = `user_link_foo`.user_id
    

    If you tell me all your table names and fields, I could help you write a more specific query.

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

Sidebar

Ask A Question

Stats

  • Questions 396k
  • Answers 396k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You cannot specify animation for Activity transition, it is not… May 15, 2026 at 2:54 am
  • Editorial Team
    Editorial Team added an answer As you've seen, the JIT can skew test results, since… May 15, 2026 at 2:54 am
  • Editorial Team
    Editorial Team added an answer It is technically possible. You'd have to host the CLR… May 15, 2026 at 2:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.