0
ActiveRecord concat 메소드를 사용하여 다른 오브젝트의 has_many 관계에 오브젝트를 추가하는 마이그레이션이 있습니다. 마이그레이션을 생성 한 이후로, 부모 모델에 유효성 검사를 포함하는 새로운 속성을 추가했습니다.마이그레이션 중에 ActiveRecord concat의 유효성 검사를 건너 뛰시겠습니까?
불행히도, concat가 부모 개체를 저장하려고 시도하고 유효성 검사에서 연결된 특성을 찾을 수 없습니다 (아직 존재하지 않음). 데이터 이전을 잘못하고 있습니까?
class RemoveTransportKeyFromInvites < ActiveRecord::Migration
def up
Invite.find_each do |invite|
transport_key = Invite.where(id: invite.id).pluck(:transport_key).first
guest_user = GuestUser.first_or_create!(transport_key: transport_key)
guest_user.invites << invite
end
remove_column :invites, :transport_key
end
def down
add_column :invites, :transport_key, :string
end
end
그리고 모델 :이 오류가 발생
class Invite < ActiveRecord::Base
# some code omitted
validates_presence_of :inviter_email
# rest of code omitted
:
undefined method `inviter_email' for #<InviteToMeal:0x007f8ece07c060>
감사가 어떤 도움을 크게 감상 할 수
여기 마이그레이션입니다!
Post 출력의 Invite.column_names – Naveed