大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 在rails中创建一个表并添加外键约束,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
现在我必须添加约束外键.学生中的任何更新/删除/编辑/插入都应对guardian_users产生相同的影响.
我怎样才能在rails 2.3.5中做到这一点?
表学生存在但其他人尚不存在.
class CreateGuardianUsersTable < ActiveRecord::Migration def self.up create_table(:guardian_users) do |table| table.@R_801_6561@amps # 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
在你的模型中:
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
以上是大佬教程为你收集整理的ruby-on-rails – 在rails中创建一个表并添加外键约束全部内容,希望文章能够帮你解决ruby-on-rails – 在rails中创建一个表并添加外键约束所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。