나는 매우 간단하게하려고 노력하고 있습니다.간단한 has_many가 작동하지 않습니다
프로필을 여러 리뷰와 연결하고 싶습니다. 지금 리뷰를 저장하려고하면 콘솔에서 BEGIN을 출력 한 다음 즉시 ROLLBACK을 실행하여 Euserprofile이 존재해야한다고 말합니다.
class EUserProfile < ApplicationRecord
has_many :EUserRevs
has_and_belongs_to_many :EUserProfiles,
class_name: "EUserProfile",
join_table: :e_user_friends,
foreign_key: :E_USER_FRIEND_TO,
association_foreign_key: :E_USER_FRIEND_FROM
has_and_belongs_to_many :EUserProfiles,
class_name: "EUserProfile",
join_table: :e_user_follows,
foreign_key: :E_USER_FOLR,
association_foreign_key: :E_USER_FOLG
end
class CreateEUserRevs < ActiveRecord::Migration[5.0]
def up
create_table :e_user_revs, {:id => false} do |t|
t.string "E_USER_REV"
t.string "E_USER_REVING", :null => false
t.integer "E_USER_SCORE", :null => false
t.string "E_USER_COMMENT", :null => false
t.timestamps
end
end
def down
drop_table :e_user_revs
end
end
class CreateEUserProfiles < ActiveRecord::Migration[5.0]
def up
create_table :e_user_profiles do |t|
t.string "E_USER_PROFILE_USERNAME", :null => false
t.string "E_USER_PROFILE_FIRST_NAME", :null => false
t.string "E_USER_PROFILE_LOC"
t.string "E_USER_PROFILE_BIO"
t.string "E_USER_PROFILE_INSTR", :null => false
t.string "E_USER_PROFILE_GENR", :null => false
t.timestamps
end
end
def down
drop_table :e_user_profiles
end
end
class EUserRev < ApplicationRecord
belongs_to :EUserProfile
end
뭐죠 here에 대한 자세한 내용을보실 수 있습니다? – max
레거시 데이터베이스로 어떤 작업을하고 있거나 현재 작업하고 있는지 전혀 알지 못합니까? – max
'EUserProfle' 클래스는 어떻게 생겼습니까? 또한, 두 개의'has_and_belongs_to_many : EUserProfiles'를 가질 수 없습니다. 어떻게 사용 중인지 구별 할 수 있습니까? 그것은'has_and_belongs_to_many : friends ... '와'has_and_belongs_to_many : followers ...'이어야합니다. 그래서'@ my_profile.friends'와'@ my_profile.followers'를 참조 할 수 있습니다.'@ my_profile.EUserProfiles' 그리고 당신이 돌아 오는 것을 알지 못할 것입니다. 또한, 천국을 위해서 수도 편지를 제거하십시오. 클래스 이름을 포함하여 상수에만 사용하십시오. – SteveTurczyn