Well, after a bit more research, I’m pretty convinced that this just
isn’t the way rails works.
According to Agile Web D. with Rails, “Notice that this table
has two foreign keys. Each row in the line_items table is associated
both with an order and with a product. Unfortunately, Rails migrations
donâ€™t provide a database-independent way to specify these foreign key
constraints, so we had to resort to executing native DDL statements (in
case, those of MySQL).”
Furthermore, the has_many relationship has a :dependent attribute that
can be set to :destroy_all, :delete_all, or :nullify. It seems to me
that it should have a :delete_restrict option, but it doesn’t.
If you are using InnoDB tables on MySQL, you can use database level
foreign key constraints that will protect the dependent rows from being
orphaned. I’ll do that, and I am reasonably confident it will work.
But it seems to me that Rails should have some method of preventing rows
from being orphaned.
Bill W. wrote:
photo matt wrote:
I managed to reproduce the same behavior in
Excellent! Please post your sandbox code. Including your SQL script
I’ve also searched the documentation and I can’t
seem to find where it says that this is the default
Not surprising. It’s an implied understanding about the way databases
You may well have discovered and reported a bug!
Good on ya, bud! And even if it’s not a bug, we’ll all learn something.