私は非常にシンプルな操作をしようとしています。シンプルな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
いただきまし凶悪列の命名スキームについての詳細を読むことができますか? – max
あなたは何をやっているのか、レガシーデータベースで作業しようとしているのか分かりませんか? – max
'EUserProfle'クラスはどのように見えますか?また、あなたは2つの '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