Skip Navigation

[Resolved] Can I avoid a many to many relationship?

This support ticket is created 2 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

This topic contains 3 replies, has 2 voices.

Last updated by Thorworx 2 years, 2 months ago.

Author
Posts
#2510493

Tell us what you are trying to do?
A many to many relationship seems to be too awkward for a site I'm redeveloping.

Is there any documentation that you are following?
All the documentation on Types post relationships.

What is the link to your site?
hidden link

I'm redesigning a site, and I want to simplify everything.
For the old site, I had set up a one-to-many CPT "Photo Competitions" (parent) with "Competition Entries" (children).
Users create Entries via a front-end form.
Everything works fine... EXCEPT:

Once a year, they have a "Year End Competition"
This Competition consists of the best (existing!) entries from the whole year.
Since Competitions are one-to-many, I had to write custom queries and add special categories in order to display the results, and I could not use my Competition templates or views, and sorting by score was a big problem.

On the new site, I thought I would change it to a many-to-many relationship, so that I could connect the entries with multiple parents (Regular Competition AND Year End Competition). This way I could use the same views/templates for everything.

It started out okay, but now I'm finding that I can't assign a parent via the front end form when the user adds a new entry, even though the form is on the parent page, and I know its ID. =( I can't use "@competition-entry.parent" on a many-to-many. Tried "competition-entry.association", but got errors. Tried a post reference field, but that didn't work, either.

It seems like the DEFAULT behavior should be to assign the current parent if the form is submitted from a parent page, then you can edit the relationship later with a relationship form or in admin if you choose to.

I understand that I can set up a CRED relationship form and do it in another step, but the users aren't too bright, and it would be difficult to get them to do this... and I'm trying to SIMPLIFY the site.

It seems silly to have to go through this for a once-a-year competition when everything else works fine with a one-to-many relationship.

Can I somehow use additional custom fields, shortcodes, custom functions (CRED save data?), or a custom intermediary post type to do this?

#2510621

If I go back to one-to-many for the Competitions, and create a SECOND one-to-many CPT called "Year End Competitions", would I then be able to add existing Entries to it without breaking the original Competition -> Entry relationship?

... or could I use a post reference field in "Year End Competitions" CPT and choose to connect existing entries that way?

#2510847

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

Reading through your first post I was going to suggest what you posted in the second: keep your existing one-to-many relationship, and add a separate one-to-many relationship for the year-end competitions (parent) and competition entries (child). The child posts can only have one parent from a give relationship, but can be children of various parents from different relationships.

#2511035

Thanks, Nigel!
This will definitely work for me.
btw, the relationship documentation is not great on this... and most of the docs describing front-end form creation rely on inserting fields and text fields- which are still broken. =(