hi,
i have a problem that involve mysql. i habe two tables: groups,ranks
ranks have a foraign key from groups with delete on cascade.
In my ranks migration i use this
execute ‘ALTER TABLE ranks ADD FOREIGN KEY (group_id) REFERENCES groups
(id) ON DELETE CASCADE;’
if i do the following in the mysql console i get an empty result as
expected.
DELETE FROM groups WHERE id=3; SELECT * FROM ranks WHERE group_id=3;
BUT here comes the Problem:
Group.find(3).destroy
Rank.find_by_group_id(3)
returns several ranks!!
First when i add “sleep 3” between these commands it works
returns nil as expected
but thats not the solution i really want…
is it a rails bug or mysql problem?
Rank.find_by_group_id(3) should first be executed if the
delete-statement(with delete on cascade) is finished.
is this shitty behaviour a rails bug or what? can some one help me out
of this?
the problem is that destroying of some childs is forbidden.
that could be overrided by setting :dependent => destroy_all
but there are much more models involved in this delete cascade stuff, so
i had to define 5 has_manys with :dependent=> destroy_all in the model
on top an for them the finder sqls cause rails can not handle has manys
through 2 models.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.