Good morning, I'm getting the following error SQLite3 :: ConstraintException: FOREIGN KEY constraint failed
The error occurs when I try to delete a record from table 'A' that is associated with a record of table 'B' through a relationship Many to Many. This is the function I use to create the table that relates A and B: #*create_join_table*(hash, options = OPTS) ⇒ Object <http://www.rubydoc.info/github/jeremyevans/sequel/Object> This is my code that links tables 'A' and 'B' migration 'create the snippets_tags table' do database.create_join_table( :tag_id=>:tags, :snippet_id=>:snippets ) end How can I delete a record from table A, or B and any relationship it has is deleted too? I have in mind something like foreign_key: tag_id,: tags,: on_delete =>: cascade,: on_update =>: cascade foreign_key: snippet_id,: snippets,: on_delete =>: cascade,: on_update =>: cascade But I'm not sure if it's the right way. This is the code that triggers the exception, it is a test: context 'delete snippet that does relations with any tag' do it 'should delete the snippet' do Tag.create(:name=>'javascript', :description=>'language').save @snippet.add_tag(Tag.first(:name=>'javascript')) expect(Snippet.all.length).to eq 1 @snippet.delete # ConstraintException :'( expect(Snippet.all.length).to eq 0 end I appreciate any help. -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
