Referential Integrity

automan25

Member
As I've mentioned in another post, I have two lists that are related to one another. One is the parent (the one side of the relationship), the other is the child (the many side of the relationship.) When a record is deleted in the parent list I would like all of the children in the child list to be deleted as well. Currently the two lists are joined by a databasejoin element. I do not see any option for cascade delete. Is there some other way I'm supposed to achieve this?
 
That'll only work if you have a list join.

Currently the two lists are joined by a databasejoin element

Well, that doesn't really "join" them, it just relates them.

Do you actually have a list join?

-- hugh
 
That'll only work if you have a list join.



Well, that doesn't really "join" them, it just relates them.

Do you actually have a list join?

-- hugh
I do not actually have a list join. I was wondering what the difference was between a join and just using the databasejoin element. You comment seems to explain it a bit. I plan on messing around with it more today.
 
Well, a database join element is just storing an FK (foreign key) value into the element. It doesn't actually do any joining in the list sense. So all you get when displaying the list is that element (showing whatever label you selected). A list join actually joins rows of data together.

-- hugh
 
Thanks, both of you. I put together a couple of parent/child lists just to test things out and got it working. Now when I delete the parent, all of the related children delete as well. In addition, by also using the database join element on the foreign key field in the child list I'm able to create a copy of the child list in a module on the same page as the detail view for one of the parent records and it shows a filtered list of children related to that parent. When I click 'add' on this module the form to add a child element correctly assigns it to the parent. Pretty slick.
 
I know this thread is a couple of months old not, but my next question is along the same line of thought. Say an element has multiple child elements. Is there a way to employ referential integrity on select child lists rather than all of them?
 
Assuming you mean "Say a list has multiple joins", rather than "an element has multiple child elements".

No. The option to "Delete Joined Data" is on a per list basis, and applies to all joins for that list. It isn't over-rideable on a per-join basis.

if you needed to do that, you'd have to do it by hand, either with a php-events list plugin, and write your own code for onDeleteRows, which would handle deleting the related child rows for the joins you want that to happen for, or outside of Fabrik entirely, with some MySQL triggers.

-- hugh
 
Thanks for the reply. What I had were joins from a child list to a parent list, which I'm now understanding is kind of bad form in database design. I had done this in order to get access to data fields from the parent list while viewing the child list. I've since deleted these joins and have found another way to do what I needed to do.
 
It's not really "bad form", and in fact is how one-to-many relationships have to work, with an FK (foreign key) on the child pointing to the PK of the parent. One-to-one joins can work either way, with the FK on the parent pointing to the child, or vice versa. Or both (so both rows point to each other), although that can get complex to manage.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top