Well, the problem is most likely in my (not) understanding the concept
of cascade deletion. In my case, I try to create an interface
application for network load tests. Each time I run a test with certain
params I want them to be stored so the user can see them and repeat test
whenever he wants. This is done by the "tests" table, in addition user
should be provided with detailed analysis of message counts through
"test_counts" table and errors through "test_errors" table (not in
example). For each test I generate unique test_id (actually timestamp)
which identifies test together with its results. I want to make sure,
that when a user deletes a record of a certain test in the "tests" table
then all the appropriate records in "test_counts" and "test_errors" get
deleted as well. I tried it with table as you can see in my first post,
but the "test_counts" entries remained in table although the test_id was
referenced correctly and I am not able to modify it to be working as
expected and described. I could actually use a autogenerated "id" but
then it should work in the first place, shouldnt it?
Thank you, Jan
Dne 4.3.2012 21:10, Anthony napsal(a):
Thanks for your quick response, Anthony. If I got it correctly, it
would be working as expected if I changed the test_id type from
integer to id. I gave it a try, but it only raised some errors
(missing required field)
Changing "test_id" to type "id" should work, but you might need to
start with a fresh table, as an "id" type field is an
auto-incrementing integer field.
and more importantly, it did not allow me to insert this field
manually. Is there some other approach to reference other value
than id?
You wouldn't set the value of an id field manually. Why do you need a
separate test_id field -- if it is unique per record, the
automatically generated id field should work? In any case, why do you
need test_counts.test_id to be the tests.test_id field rather than the
tests.id field? In the latter case, you can still access the
tests.test_id field (via a join or second query), and cascading
deletes will work fine as well (i.e., when a record in tests is
deleted, referencing records in test_counts will also be deleted).
Anthony