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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:39:09+00:00 2026-05-26T15:39:09+00:00

if our situation is the standard view where you have two tables and a

  • 0

if our situation is the standard view where you have two tables and a ternary, and easily manageable by following the following documentation

But if we have three instead of two tables and then the ternary consists of 3 PrimaryKey, as I write my yml files?

Example to situation:

Take the case that I have a user who participates in a course.
So I have a users table, courses table and a users_has_courses (useri_id, course_id).
This is the standard case many-to-many.
But I also have a table invoices and therefore a table users_courses_invoices where there are three primaykey (user_id, course_id, invoice_id).

  • 1 1 Answer
  • 1 View
  • 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-26T15:39:09+00:00Added an answer on May 26, 2026 at 3:39 pm

    In your situation you have the User and the Course model and they are linked with a many to many relation which has the pair (user_id, course_id) as key. I would call this model subscription, and give to that its own identifier, and then I will link this model with the Invoice model, so your final scheme (minimal version) could be:

    User:
      columns:
        id:
          type: integer
          primary: true
    
    Course:
      columns:
        id:
          type: integer
          primary: true
    
    Subscription:
      columns:
        id:
          type: integer
          primary: true
        user_id:
          type: integer
          notnull: true
        course_id:
          type: integer
          notnull: true
      relations:
        User:
          foreignAlias: Subscriptions
        Course:
          foreignAlias: Subscriptions
    
    Invoice:
      columns:
        id:
          type: integer
          primary: true
        subscription_id:
          type: integer
          notnull: true
      relations:
        Subscription:
          foreignAlias: Subscription
          foreignType: One
    

    In this way you have a normalized database and you can access invoices both from users and from courses with this code:

    $user->Subscriptions->getFirst()->Invoice
    $course->Subscriptions->getFirst()->Invoice
    

    If you want all invoices for a given users you can do a query in this way

    InvoiceTable::getInstance()->createQuery('i')
        ->select('i.*')
        ->leftJoin('i.Subscription s')->leftJoin('s.User u')
        ->where('u.id = ?', $user_id);
    

    The same apply if you want all the invoices for a given course.

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

Sidebar

Related Questions

We've encountered the following situation in our database. We have table 'A' and table
I have following situation: I'm developing an address-application to store the details of our
I have a situation where our developers extended a Third party database (MS SQL)
Here is our situation: We have the paid version of MonoTouch and we are
Here's our situation: We have some native code that scans user-defined directories at certain
Our situation is as follows, but I'm curious about this problem in any situation.
I'm having a problem with the knockout-mapping plugin with IE8. Our situation is that
Situation: I'm working with Adobe Livecycle ES2 and Flex In our project we show
I came across this situation while migrating our DB from Foxpro to SQL. Below
We are in a situation whereby we have 4 developers with a bit of

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.