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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:26:33+00:00 2026-05-20T19:26:33+00:00

I have a table students with field ward_id and I have to create a

  • 0

I have a table students with field ward_id and I have to create a table named guardian_users with fields id,ward_id,email,guardian_id,hashed_password etc.

Now I have to add constraint foreign key. Any update/delete/edit/insertion in students should have same effect on guardian_users.

How can I do that in rails 2.3.5?

Table students exists but other one doesn’t exist yet.

  • 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-20T19:26:34+00:00Added an answer on May 20, 2026 at 7:26 pm

    You’ll either need the foreign_key_migrations plugin or the #execute method. Assuming you go with the plugin:

    class CreateGuardianUsersTable < ActiveRecord::Migration
      def self.up
        create_table(:guardian_users) do |table|
          table.timestamps # I find them useful; YMMV
          table.integer :guardian_id
          table.integer :ward_id, :null => false, :references => [:students, :id]
          table.string :email
          table.string :heahead_password
        end
      end
    
      def self.down
        drop_table :guardian_users
      end
    end
    

    And in your models:

    class GuardianUser < ActiveRecord::Base
      belongs_to :student
    end
    
    class Student < ActiveRecord::Base
      has_many guardian_users:, :foreign_key => 'ward_id', :class_name => 'GuardianUser', :dependent => :destroy
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Help a sqlite n00b out, please. I have two tables CREATE TABLE students (
I have a database with 3 tables. The first table contains students with fields
I'm attempting to create a table called Students, with only one field, student_name. student_name
I have table with fields: email , password_hash and salt . On user registration,
I have a table (session_comments) with the following fields structure: student_id (foreign key to
i have a table Students which contains the following colums: Id,FirstName,LastName,Adress . The colum
I have a table that looks like this for about ~30 students: StudentID Course*
I have a table of student scores. Students can take the test multiple times,
I have a database table named 'student' in which there is one column named
I have three tables. The designs were like student table create table student (studID

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.