2010-08-11 5 views
0

좋은 아침 모든 레일 IRB에 변경 사항을 저장하기를 거부하고, 어떤 이유로, 나는 그것이있는 객체에 대한 변경 사항을 저장 얻을 수 없다 내가 IRB에서 디버깅 할 때 질문. 아무도 내 문제를 지적 할 수 있는지 궁금 해서요. 나는 IRB를 불 때개체</p> <p>는 내가 일하고 있어요 연관을 가지고,

class User < ActiveRecord::Base 
    has_and_belongs_to_many :affiliates 
    has_one :managed_affiliate, :class_name => "Affiliate", :foreign_key => "manager_id" 
end 

class Affiliate < ActiveRecord::Base 
    has_and_belongs_to_many :users 
    belongs_to :manager, :class_name => "User" 
    #The affiliates table has a foreign key field of manager_id 
end 

, 나는이 User.first 및 Affiliate.first을 잡아 수 있습니다 : 여기

협회입니다. 사용자의 managed_affiliate를 올바르게 설정할 수 있습니다. 그러나, 저축 할 때, 그것은 가입에서 전혀 반영되지 않는다 - 그것은 매니저가 없다. 마찬가지로, 나는 제휴사의 매니저를 잘 정할 수있다 (Affiliate.first.manager = User.first). 모든 것이 좋아진 것처럼 돌아 오지만 저장하려고하면 단순히 "false"를 반환합니다. IRB 로깅 기능을 활성화하면 다음 메시지가 출력됩니다.

SQL (0.1ms) BEGIN 
SQL (0.2ms) ROLLBACK 

이 연결이 제대로 저장되지 않는 이유는 무엇입니까?

또한, 여기에 계열사 테이블에 대한 스키마는 다음과 같습니다

create_table "affiliates", :force => true do |t| 
    t.string "name" 
    t.string "website" 
    t.integer "market_id" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    t.string "logo_file_name" 
    t.string "logo_content_type" 
    t.integer "logo_file_size" 
    t.boolean "track_subs" 
    t.integer "manager_id" 
    end 

어떤 도움 주셔서 감사합니다.

답변

1

ActiveRecord::Base#save 유효성 검증이 실패하거나 모델의 before_* 콜백이 false를 리턴하면 false를 리턴합니다.

+0

브라우저를 통해 관리자를 추가하는 빠른 양식을 작성했을 때, 그것은 챔피언처럼 작동하기 때문에 유효성 검사와 관련이있을 것입니다. 감사합니다. –