2011-07-25 7 views
0

で「MySQLの::エラー未知のコラム」エラーRoRの2.3.11で、レガシーコードでこのモデルを考えるの引き上げ例外:私は全体のほぼ同じコードを持つwith_scopeはRoRの2.3.11

create_table "assignments", :force => true do |t| 
    t.date "created_at" 
    t.date "date_assigned" 
    t.time "time_assigned" 
    t.integer "source_person_id" 
    t.integer "destination_person_id" 
    t.integer "laptop_id" 
    t.text "comment" 
    end 

    add_index "assignments", ["destination_person_id"], :name => "assignments_destination_person_id_fk" 
    add_index "assignments", ["laptop_id"], :name => "assignments_laptop_id_fk" 
    add_index "assignments", ["source_person_id"], :name => "assignments_source_person_id_fk 

    create_table "place_dependencies", :force => true do |t| 
    t.integer "descendant_id" 
    t.integer "ancestor_id" 
    end 

    add_index "place_dependencies", ["ancestor_id"], :name => "place_dependencies_ancestor_id_fk" 
    add_index "place_dependencies", ["descendant_id"], :name => "place_dependencies_descendant_id_fk" 

Assignment Delete all (0.0ms) Mysql::Error: Unknown column 'place_dependencies.ancestor_id' in 'where clause': DELETE FROM `assignments` WHERE (`id` IN (17)) AND (place_dependencies.ancestor_id = (1)) 

私のスキーマは、このようになります複数のモデルがありますが、すべてがうまく機能します。この問題にどのように取り組むべきか、ヒントを教えてください。

答えて

0

次の操作を実行した後にそれが動作:この答えはRailsの開発者に、より経験のあるルビーから見直しが必要である

def self.setScope(places_ids) 
    find_include = { 
     :laptop => { 
     :owner => { 
      :performs => { 
      :place => :ancestor_dependencies} 
     } 
     } 
    } 
    find_conditions = {"place_dependencies.ancestor_id" => places_ids} 

    Assignment.all :joins => find_include, :conditions => find_conditions 
    yield 
    end