Home › Toolset Professional Support › [Resolved] cascading deletes
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
Tagged: Post-relationship
This topic contains 19 replies, has 2 voices.
Last updated by ScottM9386 6 years, 4 months ago.
Assisted by: Shane.
Hello,
using most current version.
For many to many relationship, I see cascading deletes works if the intermediary post is NOT visible, correct?
Can I get cascading deletes working when the intermediary post is visible? currently it leaves orphan children.
Thank you,
Scott.
Hi Scott,
Thank you for contacting our support forum.
Could you let me know how this cascading delete is done ? because i'm checking on our system and our documentations and i'm not able to find any reference to it.
Thanks,
Shane
Hi Shane,
Meaning - in a many2many relationship where the intermediary post is visible, when deleting one of the parents the child (the intermediary) should also be deleted. Otherwise one gets "orphan" children in the views that have as their "content selection" the intermediary post type. I thought the term was "cascading deletes" but I could be wrong.
There's a post about it here but it's old, so not sure if this code would still be valid. If it is still valid code would it go in functions?
https://toolset.com/forums/topic/delete-all-children-cpt-when-delete-parent-cpt/
I need my intermediary to be visible because I need to start my view from there. I don't think there's anyway to create this particular view without starting from the intermediary.
you can see the view (work in progress!) here:
hidden link
Works-Tracks (one2many)
Pitches-tracks (many2many) with intermediary visible
works-publishers (many2many) with intermediary invisible.
the view has
track title, genre, tempo, descript, mood (ALL fields of "Works"), Alt Title Pitched (a field of Pitches-tracks visible intermediary), Client (a post ref field from Pitches).....etc.....
Thanks!
Scott.
Hi Scott,
I understand what you're trying to say but as mentioned i'm not aware of an inbuilt feature for the deleting of the child posts for M2M relationships.
Was this done using custom code ?
If this has not been added then I can open up a feature request for this but I need to know how is it that you deleted the Parent and the Child gets deleted for M2M relationships.
Thanks,
Shane
this?
There's a post about it here but it's old, so not sure if this code would still be valid. If it is still valid code would it go in functions?
https://toolset.com/forums/topic/delete-all-children-cpt-when-delete-parent-cpt/
Hi Scott,
I see but this custom code in this link is for a O2M relationship.
M2M relationships are more complex as we can't simply delete it if 1 parent gets deleted because that child post can have multiple parents.
Either way the custom code to do this for all the checks would be out of the scope of our support forum.
Thanks,
Shane
Understood - thanks...
so the next question is...is the same view (that I outlined above) doable without the intermediary being visible?
hidden link
Very important to note that since the same track can have many "pitches", and I need this in table format, then the rows of the table could look something like.....
Track #1 | Pitch #1
Track #1 | Pitch #2
Track #1 | Pitch # 3
get it?
Is this view possible with an "invisible" intermediary?
Thank you.
Scott.
Hi Scott,
To get it clear we have moved from the deleting issue and onto a display issue correct?
And you want to display Both Parent and Child but not the intermediary Correct?
Just need some clarification so I know exactly whats up.
Thanks,
Shane
Hi Shane,
"To get it clear we have moved from the deleting issue and onto a display issue correct?"
Correct
"And you want to display Both Parent and Child but not the intermediary Correct?"
Incorrect.
My set up and the view I'm trying to create:
I have the following CPT's
Works
Tracks
Publishers
Clients
Pitches
The Relationships are:
Works - Tracks (one2many)
Works - Publishers (many2many) - has intermediary cpt with fields
Pitches - Tracks (many2many) - has intermediary cpt with fields
Pitches has a post reference field to Clients.
I need to do the following view as a table (columns not necessarily in this order)
Track Title | Pitches field X | Pitches intermediary cpt field X | Pitches post reference to Client Title | Work Field X | Publisher Title | Publisher intermediary cpt field X |
Very important to note that since the same track can have many "pitches", and I need this in table format, then the rows of the table could look something like.....
Track #1 | Pitch #1 | etc...
Track #1 | Pitch #2 | etc...
Track #1 | Pitch # 3 | etc...
I can do this view if the Pitches - Tracks intermediary is VISIBLE. But I would like to have the intermediary be "invisible".
The reason:
If the intermediary is visible and one deletes a parent you get orphan children. in the VIEW.
If the intermediary is INVISIBLE and one deletes a parent you DON'T get orphan children in the VIEW.
Thank you!
Scott.
Hi Scott,
So for this particular view you want the intermediate cpt to be displayed in the same row.
So when you're adding the post fields in the view. There is a post selection option when adding the shortcode, click on "A post related to the current post, set by a Types relationship" then select the intermediary CPT.
Please let me know if this is ok.
Thanks,
SHane
Hi Shane,
ah....can you elaborate a little more please?
From which post type are you suggesting I start the view?
No doubt there will be nested views, right?
can I create the table as described above with the Pitches - Tracks intermediary cpt being invisible?
I really need more details.
I have no idea how your suggesting I do this view.
as I said above....
"Very important to note that since the same track can have many "pitches", and I need this in table format, then the rows of the table could look something like.....
Track #1 | Pitch #1 | etc...
Track #1 | Pitch #2 | etc...
Track #1 | Pitch # 3 | etc..."
In other words I DON'T want multiple fields in a single cell.
Do you get what I'm going after?
Thanks,
Scott.
for instance:
If I have 3 tracks, track #1, track #2 and track #3 and the 3 tracks are attached to 3 different pitches + there's an intermediary between them with fields. So - the table would have 9 rows and would look like:
Track #1 | Pitch #1 | Intermediary field
Track #1 | Pitch #2 | Intermediary field
Track #1 | Pitch #3 | Intermediary field
Track #2 | Pitch #1 | Intermediary field
Track #2 | Pitch #2 | Intermediary field
Track #2 | Pitch #3 | Intermediary field
Track #3 | Pitch #1 | Intermediary field
Track #3 | Pitch #2 | Intermediary field
Track #3 | Pitch #3 | Intermediary field
Currently the only way I know how to do this is by making the intermediary VISIBLE
BUT - I DON'T want it visible - I want it invisible for the reasons outlined above.
Plus, I think when the intermediary is visible the querying seems to be VERY slow.
Thanks.
Hi Scott,
The intermediary can be attached to any view. For me I would add the intermediary to the child view.
So you will only need to create 2 views. 1 View to display the parent and then the Child view can display the intermediary and the child post.
I can help better with this if you provide me with the credentials to help.
Thanks,
Shane
Hi Shane,
Thank you for your help.
But I'm afraid what I'm asking is much more complicated.
If you could tell me this please:
Is it possible to create a view, as a table, where, say, the title of the INVISIBLE intermediary occupies it's own row.
Like so:
INTERMEDIARY TITLE: | etc. |
Intermediary #1 | etc. |
Intermediary #2 | etc. |
Intermediary #3 | etc. |
If this can be done then I think the view I need can be achieved....sadly I don't think it can with an invisible intermediary.
The view you describe will put multiple posts in one cell.
This view will not parse out each track - pitch - intermediary to one row.
For instance, it will either put multiple track titles in one cell for each pitch OR multiple Pitch titles in each cell for each track...
Your view will not look like this: (each one of these lines is a row. - 6 rows)
Track #1 | Pitch #1 | Intermediary field
Track #1 | Pitch #2 | Intermediary field
Track #1 | Pitch #3 | Intermediary field
Track #2 | Pitch #1 | Intermediary field
Track #2 | Pitch #2 | Intermediary field
Track #2 | Pitch #3 | Intermediary field
PLEASE see the attached image of an example of the difference between the view your describing and the view I need.
Thank you,
Scott.
Hi Scott,
Ahh i see what you want now.
No its not going to be possible because of how the view loop works. I might not want to say its impossible to achieve because it would take some trial an error.
But thinking about it, it would be possible with just one view, since there is an intermediary and a parent/
Try this.
Create a view for the child post. Then on that child post you'll have it pull the intermediary CPT title and the Parent title including the current post title
Example
[wpv-layout-start] [wpv-items-found] <!-- wpv-loop-start --> <table width="100%"> <tbody class="wpv-loop js-wpv-loop"> <wpv-loop> <tr> <td>[wpv-post-title item="@lecturer-course.parent"]</td> <td>[wpv-post-title item="@lecturer-course.intermediary"]</td> <td>[wpv-post-title]</td> </tr> </wpv-loop> </tbody> </table> <!-- wpv-loop-end --> [/wpv-items-found] [wpv-no-items-found] <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong> [/wpv-no-items-found] [wpv-layout-end]
So in this case we have Lecturers -> Intermediary -> Course. This view is listing courses.
Please let me know if this helps.
Thanks,
Shane