But is there any way I can add integrity constraints to the create_join_table function?
2017-09-27 8:16 GMT-04:00 Carlos Azuaje <[email protected]>: > Gracias por tu respuesta Jeremy, he usado este codigo y mi test a pasado. > > migration 'create the snippets_tags table' do > database.create_table :snippets_tags do > foreign_key :tag_id, :tags, :null=>false, :on_update => :cascade, > :on_delete => :cascade > foreign_key :snippet_id, :snippets, :null=>false, :on_update => :cascade, > :on_delete => :cascade > primary_key [:tag_id, :snippet_id] > index [:tag_id, :snippet_id] > end > end > > > 2017-09-26 21:50 GMT-04:00 Jeremy Evans <[email protected]>: > >> On Tuesday, September 26, 2017 at 5:10:36 PM UTC-7, Carlos Azuaje wrote: >>> >>> 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 expected relational behavior if you aren't cascading deletes. >> You need to delete the entries in the join table related to the row being >> deleted from table A before deleting the row from table A. >> >> You should be able to use the association_dependencies plugin if you want >> a model-level solution that deletes associated rows in the join table >> before deleting the current row. But it's probably best to cascade deletes >> the in the database instead of trying to emulate it at the model layer. >> >> Note that cascading deletes in general, either in the database or the >> model layer, is a fairly sharp knife that should be used with caution. >> >> Thanks, >> Jeremy >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "sequel-talk" group. >> To unsubscribe from this topic, visit https://groups.google.com/d/to >> pic/sequel-talk/1l9qSmVfg14/unsubscribe. >> To unsubscribe from this group and all its topics, 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. >> > > -- 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.
