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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:11:58+00:00 2026-06-02T07:11:58+00:00

I’m getting confused with (mentally) connecting databases and object-oriented programming. Imagine a teacher’s gradebook

  • 0

I’m getting confused with (mentally) connecting databases and object-oriented programming.

Imagine a teacher’s gradebook application, for example, with a UI displaying students in a table’s row and assignments in columns. An underlying database might include a many-to-many relationship: a student has many assignments, and an assignment has many students.

How does the underlying code work? Do you have a Student class with a variable referencing a list of assignments? Or an Assignment class with a variable referencing a list of students? Both? … Do you have some kind of StudentAssignment class linking instances of Student and Assignment? (And, if so, does that mean a class with 50 students and 10 assignments has 500 StudentAssignment objects, 50 Student objects, and 10 Assignment objects in memory simultaneously?!) … And then do these various classes consist mostly of (for example) SQL statements working with the underlying database?

I know there’s a lot of questions here, but they all kind of go together…what’s the generally accepted strategy for coding many-to-many relationships?

p.s. Just so you don’t think I’m being lazy, I did look at other questions, like a How to model a Many to many-relationship in code? and Modelling a manyToMany relationship with attributes.

  • 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-02T07:12:00+00:00Added an answer on June 2, 2026 at 7:12 am

    In the database you would need a Student Table, an Assignment table, and an intersection table of StudentAssignment. The OOP representation of this could just be each student having a collection of their assignments. Do you need to see what students have a particular assignment? If you do, than by all means populate that information on the Assignment objects. Or, you could also check every student for having a particular assignment.. It’s up to you.

    Database have limitations in how the data is represented and accessed that you don’t necessarily have in an OOP language.

    You definitely do NOT need a StudentAssignment object though. That table expresses a relationship, not an entity.

    EDIT:

    If you needed to go from the assignment to the students who have that assignment, as well as from the student, to all of their assignments, you would need the 50 student objects, and 10 assignment objects. When you create these objects, you would want to populate collections on each of those objects with their associated objects (A Student would have a List Assignments and vice versa).

    Let’s say you did this:

    Create objects for all of your Students(this returns 50 records), setting their Assignments collection to an emty list.

    SELECT
        StudentName,
        ID
    FROM
        Student
    

    Create objects for all of your Assignments(this returns 10 records), setting their Students collections to an empty list.

    SELECT
        AssignmentName,
        ID
    FROM
        Assignment
    

    Lets say that you queried for all of the data with something like: (Assuming each student has each assignment, this returns 500 records)

    SELECT
        Student.ID [StudentID],
        Assignment.ID [AssignmentID]
    FROM 
        Student
        INNER JOIN StudentAssignment ON Student.ID = StudentAssignment.StudentID
        INNER JOIN Assignment ON Assignment.ID = StudentAssignment.AssignmentID
    

    You would want to loop through these 500 records, adding the corresponding objects for each relationship. You would still only have those 60 objects (50 + 10), but their relationships would be defined by the collections of Assignments or Students that each object has.

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

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a 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.