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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:08:47+00:00 2026-05-22T21:08:47+00:00

I have 2 models – Batch and Player Batch has_many :players, :foreign_key => PL_BATCH

  • 0

I have 2 models – Batch and Player

Batch has_many :players, :foreign_key => "PL_BATCH"
Player belongs_to :batch, :foreign_key => "PL_BATCH"

The table batches contains the following fields:

-BA_OID (defined as the primary key)
-BA_BATCH_ID
-BA_NAME

The table players contains the field PL_BATCH which is the foreign key of BA_BATCH_ID.

Note that I am using a legacy database and the column ‘BA_OID ‘ is defined as the primary key of the batches table in mysql. However BA_BATCH_ID is used as FK in the players table

Batch model:

  set_table_name "batches"
  set_primary_key "BA_OID"
  has_many :players, :foreign_key => "PL_BATCH"

How do i define the relationship between batch and player models??

Thank you for your help

  • 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-22T21:08:48+00:00Added an answer on May 22, 2026 at 9:08 pm

    You’re almost there! Try the following…

    Batch:

    has_many :players, :primary_key => "BA_BATCH_ID", :foreign_key => "PL_BATCH", :class_name => "Player"
    

    Player:

    belongs_to :batch, :primary_key => "BA_BATCH_ID", :foreign_key => "PL_BATCH", :class_name => "Batch"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let us say we have models as such: Trigger belongs_to :position Position has_many :trigger
I have models: Transaction has_many :credits, :debits Credit belongs_to :transaction Debit belongs_to :transaction Each
I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #
I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =>
I have models similar to the following: class Band(models.Model): name = models.CharField(unique=True) class Event(models.Model):
Let's say I have models that look like this: class Foo < ActiveRecord::Base has_many
I have models A and B. A has_many B. In the edit view for
I have models in project that use more than one table to select. How
Hi I have two Modules on each modules i have models with table class,
I have models in my app: class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic =>

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.