Skip Navigation

[Resuelto] Relationships with multi-field key

This support ticket is created hace 4 años, 9 meses. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 16 respuestas, has 2 mensajes.

Last updated by paulB-10 hace 4 años, 9 meses.

Assisted by: Christian Cox.

Autor
Mensajes
#1261129

My situation is similar to
https://toolset.com/forums/topic/multiple-nested-relationships-for-sports-league/

I am trying to set up a relationship for players who want to play in a competitions.
Over time we want to know whichh compeitions players played in.
E.g. 2018 Mens Open European Championship
2018 Womens Open European Championship
2019 Mens Open World Cup
2019 Womens Open World Cup
Player1 played in the 2018, mens open European Championships, 2019 Mens Open World Cup
Player2. played in the 2019 Mens Open World Cup

So we have a many to many relaitonship.

Is one solution to create a block code for each tournament which would have to exist in both the player and tournament custom post.
e.g. 2018EUROMO
2019WORLMO
and use that in the relationship so it would be

Player1 2018EUROMO
Player1 2019WORDMO
Player2 2019WORLWO

If thie block code is the solution, how do I then create the relaitonship, search, etc for this setup .
Is there an article that covers this.

Thank you in anticipation.

#1261417

Hi, can you tell me more about exactly what you want to achieve? What do you mean by "search", exactly? What filters will be used?

#1261443

My first goal is to understand the best way to build the custom post types to best use the relationships.
Then, when we do the search the coach/manager will be looking at a list of players in his team e.g. 2019 World Cup Mens Open team

#1261505

At a very basic level you need two post types in a many-to-many post relationship. You may need to add custom fields to the intermediary post type, I"m not sure based on the information I have here. For example, if you need to know which position each Player played in the Tournament, then you would need to store that information on the intermediary post type.

If you need the ability to search and filter the lists of Players based on their position, or their height or weight or whatever information, I need to know about those things so I can tell you the best way to set it up.

#1261515

Thank you for that additional information which is really useful and I can use that.

My initial question is really about the player-tournament relaitonship. a tournement does not have a single field that uniquely identified a tournament as per my example
2018,European chanpionship, Men's Open
2019, World Cup, Women's Open
As you can see I need the 3 fields to uniquely idenfity the tournament.
Hence my query about creating a primaty (custom post id ) which is a block code
e.g. 2018ERUOMO for 2019 Eoro=European Championship, MO = Men's Open.
This block code would have to be on the tournment custom post type and the custom player who played in the tournment.

Can address the above question first.

I am trying to determine the best way to define this many-many relationship.

#1261579

2018,European chanpionship, Men's Open
Can you explain in more detail why these need to be 3 separate post types? Why not one Tournament post 2018 European Championship Men's Open? What is the purpose of splitting these up? I'm trying to understand why you want it this way.

#1261593

Hi
2018,European chanpionship, Men's Open are the three fields in the tournement custom post type.
The indicate we entered a Mens Open team in the 2018 European Championship.
to uniquely identiry a tournament you need the three fields.
hence you need the three fields to link to a player to indicate the players who played in that tournament.

#1261603

This doesn't really answer my question. I'm still not clear why you need 3 fields. Are they used as filters for searching? If not, why do you need 3 fields? Why not just make the name of the tournament unique? What is the purpose of the fields?

#1261605

That is why I asked if I should create an addtional field, the block coded field
e.g. 2018EUROMO to represten the tournemnt. (the unique id)
If i make a single field with the three values it makes it difficult to search on just Men's Opon etc. or who played in all the 2018 tournaments.

#1261617

Okay let's say you have a View of Tournaments. This View has 3 filters:
- Year (2018, 2017, etc.)
- Competition (European Championship, World Cup, etc.)
- Division (Mens Open, Womens Open)

Your site visitors can choose any of the 3 filters, and then they can see a list of all the Players in that Tournament, Correct? If so, you do not need any additional blockcode. There is no need for it. You only need the 3 filters in a View of Tournaments.

Then you will create a View of Players, filtered by post relationship, where the parent Tournament is set by the current post in the loop. Insert this View of Players in the loop of the View of Tournaments. So now you have a nested View structure. If you would like, I can show you an example of this in a test site at https://discover-wp.com.

#1261621

yes, that sounds like what I am looking for.
Can you point me to the example
Thanks

#1261645

Yes please create a free account at discover-wp.com, then let me know which email you used to sign up. I will invite you to collaborate on a test site with me.

#1264449

Hi
Apologies for the delay, other things needed attending to.
I have set up the acocunt.
Regards
Paul Brown

#1265567

Okay I just sent you an invitation. Please check your email. When you log in to the site, you can see the search View here: hidden link

You can check out the two nested Views here:
hidden link
hidden link

Then you can inspect the Tournaments and Players in wp-admin.

#1266525

Hi Christian
Thank you for supplying the test cases.
I am trying to understand the efficiency of the underlying database design, especiall the intermediate table or view.
I enabled the show-ui so I could see the tournament-player in the men, expecting to see the fields that made up the intereidate table.
1. Is the intermediate table a view or a real db table.
2. If it is a table does it contain the player post title and the 3 fields from the tournament to uniqule determine the relationship. or just the post ids from each custom post type.
3. If you are able tp supply a screen shot of the intermediate table from the DB , that would answer my question.
4. My thoughts are that the intermeidate table only really requires the unique id of the tournament post and the unique post id of the player post type. as per this entry
Players Tournaments: 1335 – 1343

Regards
Paul Brown

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.