title: ActiveRecord use SQL foreign_key with on_delete cycles
body: <p>I have</p>
  
  <pre><code>class Organization &lt; ActiveRecord::Base
    has_one  :contact, :inverse_of =&gt; :organization, :foreign_key =&gt; 'organization_id'
    has_many :contacts, :inverse_of =&gt; :address_book, :foreign:key =&gt; 'address_book_id'
  end
  </code></pre>
  
  <p>I would like to add a SQL constraint so when a company is deleted, both its contact and contacts are deleted.</p>
  
  <p>I therefore add (since I am Rails > 4.2) to my migration:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>but this raises </p>
  
  <pre><code>TinyTds::Error: Introducing FOREIGN KEY constraint 'fk_rails_7e223a7fac' on table 'contacts' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.: ALTER TABLE [contacts] ADD CONSTRAINT [fk_rails_7e223a7fac]
  </code></pre>
  
  <p>(I use SQL Azure with TinyTds and ActiveRecord sql adaptor).</p>
  
  <p>From what I understand, this occurs since if a same organization is referenced by a Contact on both :contact and :contacts, it will have multiple cascade paths. Now, how can I still have cascading with such a setup?</p>