ActiveRecord使用带有on_delete周期的SQL foreign_key

时间:2015-10-20 15:28:03

标签: sql ruby-on-rails sql-server activerecord

我有

var obj = {
    'ABC': {
        id: '123',
        name: 'Sesame Street'
    }, 
    'DEF': {
        id: '123',
        name: 'Sesame Street'
    }, 
    'GHI': {
        id: '456',
        name: 'Nowhere Street'
    }
};

console.log('Get length of obj', _.size(obj));
console.log('Get length of obj with id == 123??');

我想添加一个SQL约束,以便在删除公司时删除其联系人和联系人。

因此我添加(因为我是Rails> 4.2)到我的迁移:

class Organization < ActiveRecord::Base
  has_one  :contact, :inverse_of => :organization, :foreign_key => 'organization_id'
  has_many :contacts, :inverse_of => :address_book, :foreign:key => 'address_book_id'
end

但这会引发

def change
  add_foreign_key :contacts, :organizations, column: :organization_id, on_delete: :cascade
  add_foreign_key :contacts, :organizations, column: :address_book_id, on_delete: :cascade    
end

(我使用带有TinyTds和ActiveRecord sql适配器的SQL Azure)。

根据我的理解,这是因为如果联系人同时引用同一个组织:contact和:contacts,它将具有多个级联路径。现在,我怎么还能用这样的设置进行级联?

0 个答案:

没有答案