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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:46:42+00:00 2026-06-17T07:46:42+00:00

This may be a stupid question, and I’ve read over this: http://web2py.com/books/default/chapter/29/06#One-to-many-relation But I’m

  • 0

This may be a stupid question, and I’ve read over this: http://web2py.com/books/default/chapter/29/06#One-to-many-relation

But I’m still having troubles understanding where I went wrong with my database declaration.

Here’s the layout of what I want my tables to look like, with references and everything:

http://imgur.com/fpaDb

Here’s the web2py code that I used in db.py

db.define_table('Course',Field('CallNumber','integer'),Field('Section','string',),Field('Title','string'),Field('MinCredit','integer'),Field('MaxCredit','integer'),Field('MaxEnrollment','integer'),Field('CurrentEnrollment','integer'),Field('Status','string'),Field('Instructor1','string'),Field('Term','string'))
db.define_table('Meeting',Field('CallNumber',db.Course),Field('Day','string'),Field('StartTime','string'),Field('EndTime','string'),Field('Site','string'),Field('Building','string'),Field('Room','string'),Field('Activity','string'))
db.define_table('Requirement',Field('CallNumber',db.Course),Field('Control','string'),Field('Argument','string'),Field('Value1','string'),Field('Operator','string'),Field('Value2','string'))

What I’m trying to do is make sure that the Meeting and Requirement tables refer back to the Course table not by the arbitrary id that web2py assigns the entries in the Course table, but by the CallNumber instead.

Any help would be appreciated. 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-06-17T07:46:43+00:00Added an answer on June 17, 2026 at 7:46 am

    A reference field stores the primary key of the referenced table, which is the id field. If you want the CallNumber value of a referenced record, you can easily get it when you do a join:

    db.define_table('Course', Field('CallNumber', 'integer'), ...)
    db.define_table('Meeting', Field('Course', db.Course), ...)
    
    row = db(db.Course.id == db.Meeting.Course).select().first()
    print row.Course.CallNumber
    

    You can also do a recursive select:

    row = db(db.Meeting).select().first()
    print row.Course.CallNumber
    

    Note, the recursive select is less efficient when looping over multiple records because it does a separate database query for each record. The inner join method above is more efficient in that case, as it involves just a single query to retrieve the entire set of joined records.

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

Sidebar

Related Questions

This may be a stupid question, but are the default aliases (e.g. cd) hardcoded
This may be a stupid question but how does one actually run the 'Build'
This may be a stupid question, or at least one with some incorrect assumptions
This may sound like a stupid question, but if one locks a resource in
This may be a stupid question, as most of my programming consists of one-man
This may be a stupid question but one that is throwing me for a
This may be a stupid question but I have a code with the following
This may be a stupid question, but I'm trying to replicate a customer's OpenLDAP
This may be a stupid question, as I'm not sure how MSBuild works with
This may be a stupid question, but I have to ask! I have the

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.