2013-05-23 2 views
0

새 열을 추가하고 조건을 사용하여 다른 테이블 열의 값을 업데이트하는 방법은 무엇입니까?레일즈 마이그레이션 - 제약 조건이있는 열 업데이트

user

id: integer 
user_id: integer 
type: string 

가 지금은 새 열을 추가 할 필요가의 난 등 전자 우편, 전화, 같은 user

id: integer 
name: string 
preferred_communication_channel_id: integer // stores the id of communication_channel 

및 테이블 communication_channel 저장 다른 통신 채널 ..라는 두 개의 테이블을 데 communication_modeuser

그리고열을 업데이트하십시오. 일부 제약 여기

communication_channel.type에서값은 레일 마이그레이션에서이 쿼리를 구현하는 방법 업데이트

update user as p 
join communication_channel as cc 
on p.preferred_communication_channel_id = cc.id and p.id=cc.user_id and cc.type="Telephone" 
set p.communication_mode=3 

나는 새 열을 추가하기 위해 마이그레이션을 생성했지만 MySQL 버전을 간다?

내가 방금 execute "SELECT * FROM bananas"를 작성할 수 마이그레이션에서 아무것도

답변

0

을 놓친와 SQL이 실행 될 경우 제발 올바른!

관련 문제