Accueil › Toolset Professional Support › [Résolu] Create a relationship between brand and brandowner connected to a country
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 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9:00 – 13:00 |
14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - | - | 14:00 – 18:00 |
Supporter timezone: Africa/Casablanca (GMT+01:00)
Marqué : Setting up post relationship, Types plugin
Documentation connexe :
Ce sujet contient 12 réponses, a 2 voix.
Dernière mise à jour par AlimB3245 Il y a 4 années et 6 mois.
Assisté par: Jamal.
Tell us what you are trying to do? I have 2 custom post types ie brand and brand-owner.. normally I would have kept it as one brand is owned by one brand owner.. so let's say SONY BRAND is owned by SONY ORG.. and my website is for USA, JAPAN and CHINA.. Now SONY ORG is connected to all 3 countries for SONY BRAND... but in USA they have another brand owner (let's call him TONY ORG who is the distributor for SONY BRAND in USA) .. so I need to connect TONY ORG to SONY BRAND for USA... so SONY BRAND would have a relationship with USA, JAPAN and CHINA with SONY ORG and also have a relationship with TONY ORG for USA.
In addition, if I could specify that TONY ORG has a 'distributor' relationship and not 'brand-owner' relationship with SONY ORG, that would be really nice.. basically when I filter out BRAND OWNER custom post types, I should be able to filter SONY ORG as a BRAND OWNER (custom post type) who is a 'brand-owner' (field type) for BRAND (custom post type) for countries (not sure if it should be field or a taxonomy)
So I would be able to filter out TONY ORG as a BRAND OWNER (custom post type) who is a 'distributor' (field-type) for BRAND (custom post type) for countries (field or taxonomy)
Is there any documentation that you are following? No.. didn't know what to search..
Is there a similar example that we can see?
What is the link to your site? lien caché
Hello and thank you for contacting the Toolset support.
Before suggesting how to create relationships, I'd prefer to ask a couple of questions and understand what is the outcome you would like to get.
Do you want to filter "TONY ORG", as both, brand owner and distributor? Or just one?
Keep in mind that a Toolset view does not allow you to filter on two relationships for the moment, unless, you are ready to add some custom code.
Intermediary posts in Many-to-many relationships do not support taxonomies. They only support custom fields.
Can you elaborate more on the kind of filtered views you intend to have? Views of brands or brand owners?
Hi Jamal
Thanks for the update..:-)..
Do you want to filter "TONY ORG", as both, brand owner and distributor? Or just one?
TONY ORG would always be a brand owner as that's the custom post type .. So TONY ORG (and SONY ORG) would always be brand owners.
Being a distributor is a relationship a brand-owner has with regards to a BRAND (another custom post type that has a one to one relationshop with brand owner.. one brand - one brand owner) and a COUNTRY (custom field/taxonomy/custom post type... not sure).
(I am assuming I would need a COUNTRY as a custom post type... but I would let you decide this)
So TONY ORG and SONY ORG are connected to single or multiple COUNTRY as brand owners. This by default means that they are distributors for BRANDS (that's connected to them) for the COUNTRY (that's connected to them)
Now if TONY ORG can be added as a distributor for a BRAND (SONY BRAND) (that does not belong to TONY ORG) for a COUNTRY (USA)(TONY ORG has to be connected to this COUNTRY)
So now SONY BRAND has a BRAND OWNER who is connected to USA, JAPAN and CHINA.
It has another BRAND OWNER (TONY ORG) for USA.
It should be clear that SONY BRAND (belongs to SONY ORG) but it has a distributor relationship with TONY ORG for USA.
In JAPAN and CHINA where SONY BRAND has no such distributor relationship and is only connected to its brand owner, SONY ORG, it's implied that SONY ORG is the distributor UNLESS another brand owner is added as a distributor for JAPAN or CHINA.
Hope that helps clear the relationship required.. please feel free to put forward your queries.
I do understand that I am trying to imply a distributor relationship by way of non-existence of distributor for that store. This is to keep things simple but I hope it's the right thing to do. DISTRIBUTOR is not a custom post type.. only BRAND OWNER is a custom post type. DISTRIBUTOR is a relationship that a BRAND OWNER has with BRAND and COUNTRY that the BRAND OWNER is connected to.
Will try again to explain the relationship below.
A BRAND OWNER CAN HAVE ONLY ONE BRAND.
A BRAND CAN HAVE ONLY ONE BRAND OWNER
A BRAND IS CONNECTED TO THE COUNTRY VIA THE BRAND OWNER.
SO THAT BRAND DOES NOT EXIST FOR A COUNTRY IF THE BRAND OWNER IS NOT CONNECTED TO THAT COUNTRY.
IF A BRAND EXISTS FOR A COUNTRY, THEN BY DEFAULT, THE BRAND OWNER IS THE DISTRIBUTOR OF THAT BRAND FOR THAT COUNTRY.
A BRAND CAN HAVE ANOTHER BRAND OWNER (who is already connect to the country) ADDED AS A DISTRIBUTOR FOR THAT COUNTRY.
A BRAND CAN HAVE ONE BRAND OWNER AS DISTRIBUTOR PER COUNTRY.
A BRAND OWNER CAN BE A DISTRIBUTOR FOR MULTIPLE BRANDS BUT ONLY ONE BRAND PER COUNTRY.
Do you want to filter "TONY ORG", as both, brand owner and distributor? Or just one?
To reply to this question again... I would filter TONY as BRAND OWNER for sure.. I would want to filter him as DISTRIBUTOR for USA for SONY BRAND
When displaying all brands with their countries and brand owners, I'd like to be able to filter as below.
SONY BRAND is active in USA, JAPAN and CHINA (as the BRAND OWNER is connected to these COUNTRIES)
SONY BRAND's brand owner is SONY ORG
SONY BRAND's distributor for USA is TONY ORG
SONY BRAND's distributor for JAPAN is SONY ORG
SONY BRAND's distributor for CHINA is SONY ORG.
Regards,
Alim
Thank you, Alim, for these details. I think to have a better idea now. Correct me if I am wrong.
I understood that the relation (Brand<>Brand Owner) does not need a country linked to it. A brand owner owns a brand in all countries where is brand is active.
A brand owner is the distributor of a brand in one or more countries. It may be the owner of the brand or a different brand owner.
I'll suggest implementing:
- A one-to-one relationship or a Post Reference Field to track the ownership of a brand.
- A many-to-many relationship to track the distribution. And use a custom post type to track the country on the intermediary post type.
Read more about relationship fields in many-to-many relations here https://toolset.com/documentation/post-relationships/how-to-set-up-post-relationships-using-toolset/#relationship-fields-in-many-to-many-relations
Taxonomies are not allowed on intermediary custom posts, that's why we need to track the country in a custom field. And we will have 3 posts for the distribution of SONY:
- Intermediary post between SONY BRAND and TONY ORG with custom field country set to the USA.
- Intermediary post between SONY BRAND and SONY ORG with custom field country set to JAPAN.
- Intermediary post between SONY BRAND and SONY ORG with custom field country set to CHINA.
When displaying all results, your view should query the intermediary post type and you can pull custom fields from parent post types(Brand and Brand owner). Check this article https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/
I hope this helps. Let me know if you have any questions.
HiJamal
Thanks for the update..:-)..
Yes, we are on the right track..:-).. but I'd like to confirm a few things just to ensure there's no miscommunication..
I understood that the relation (Brand<>Brand Owner) does not need a country linked to it. A brand owner owns a brand in all countries where is brand is active.
A BRAND OWNER owns a BRAND in all countries where A BRAND OWNER (not BRAND) is active.. (as I don't really have a custom field or taxonomy for countries in the brand custom post type).. Not sure if your statement above really affects the solution provided or not.. but I just thought I'd point it out..
Based on your solution I already had a BRAND OWNER TO BRANDS relationship (One To Many) so I created a BRAND DISTRIBUTOR TO BRANDS (Many to Many) relationship..
But I can't figure out where do I add the country field to this relationshiop.. I did get the screen while creating the relationship that I could add custom fields but there was nothing on this page except the CONTINUE button that took me to the Naming of the relationship screen/section... I assumed I could add the custom field for country after I create the relationship.
But now I am not able to figure out how to find the 'intermediary custom post type' to add the custom field.. (assuming that's what I am supposed to do)..
The tutorial link too didn't provide much help in this..
I tried to go to CREATE CUSTOM FIELDS but on created I couldn't add assign the field group to the Intermediary Post (Brand Distibutor to Brand) and on editing the POST TYPE, I could find the Intermediary Post Type but on editing it I couldn't find where to add a custom field..
Please do advise..
Regards,
Alim
Hi Jamal
I finally found it..;-).. it wasn't very easy but I found it.. it was in the EDIT RELATIONSHIP at the bottom of the first screen..;-).. (screenshot attached)
Now you would see that I had 2 types of Fields created for country.. One was a SELECT so one one country at a time.. and the other a checkbox so I could select multiple country while assigning a distributor..
I realised that a checkbox might be more practical as it allowed me to add a Distributor (while editing a BRAND and Connecting the Distributor) only one time per brand owner/distributor.. so if I had to assign the same brand owner to another country using the SELECT option it wouldn't work.. but with the checkbox I could select multiple countries and work around this issue and successfully add multiple countries at the same time.
Please do let me know if this is the expected result.. I am fine with checkboxes instead of SELECT .. but I just wanted to confirm that I am not doing anything wrong .. and that being able to add the brand owner only once is the expected result (it actually works perfect for me but I am just a bit confused with the expectations of a MANY TO MANY relationship result).. I have attached the screenshot for the check box and SELECT option so that you are clear about this and are able to advise better..
Regards,
Alim
Hi Jamal
Please do confirm on the above query about checkbox and SELECT option so that I can close this ticket.
It's all working fine..:-).. thanks for the guidance and support.
Have a nice day..:-)..
Regards,
Alim
Hello Alim,
If it is working fine for you, that's fine. That's the motto of building computer systems, if it works, do not change it 🙂
But, I think, the checkbox is adding some complexity. Let me explain:
You said: A BRAND OWNER owns a BRAND in all countries where A BRAND OWNER (not BRAND) is active.
I do not see why adding the country here. It would be simpler to say that a "BRAND OWNER owns a BRAND" without giving much importance to the country.
From what I understand, the country is about distribution, that's why I thought to add it to the distribution model(M2M relationship). In some countries, the BRAND OWNER is the distributor for a BRAND, and in other countries, another BRAND OWNER is the distributor.
We will know which countries the BRAND is active on, from the intermediary posts of the distribution relationship. But the Owner is always the same, whether the Brand has a different distributor or not.
But you will have to add a distribution intermediary post (parent posts+country custom field)at a time for each country, you won't be able to add multiple countries at a time. Maybe that could justify the checkbox custom field, or maybe I am missing something.
I am glad you were able to add fields for the relationship.
I'll remain at your disposal, if you still need to discuss something, or if you have another question.
Best regards,
Jamal
Hi Jamal..:-)..
First of all thanks a million for making me 'see' what I have been blind to for sooooooooo long that I wish I had realised this method of seeing the brand's relationship much earlier!! Suddenly life seems so much simpler..;-)..
I've always tried to use the other way around (via the brand owner and somehow try to connect it to the distributor) and it's always been a HUGE pain.. but yes, your logic follows the rule i'd love to follow alway.. KISS (Keep It Simple & Stupid)..:-).. I have no idea why I was trying to do things the way I was..;-)..
But you will have to add a distribution intermediary post (parent posts+country custom field)at a time for each country, you won't be able to add multiple countries at a time. Maybe that could justify the checkbox custom field, or maybe I am missing something.
Yes, you are absolutely right.. in the M2M relationship between brands and distributors, once I add a distributor I cannot add him again (which is logical) ... so if a brand has a distributor for multiple countries, a SELECT field would not help.. hence the checkbox option.. hope I am doing things right with the checkbox, in this case..
Please do confirm, so that I can close this ticket, being sure that I finally doing things right!..;-)..
Have a nice day..:-)..
Regards,
Alim
Hello Alim and thank you for the kind words.
I just tested my first suggestion on a new install and you were right, we can't connect a Brand and a Brand Owner several times for each country. So I have been discussing this with the team and we got to the following options:
- Create multiple Brand Owners or Brands per country, exp, BrandOwners: SONY ORG JAPAN, SONY ORG CHINA, TONY ORG USA. Or, brands: SONY JAPAN, SONY CHINA, SONY USA. And then connect them to the other post type.
- Add an additional post type for Brands active countries, this post will be related to brands with a one-to-many relationship. A brand can have multiple "Brand active countries". Then reconfigure the distribution relationship to connect BrandOwner with "Brand active countries". This relationship won't need to have custom fields on it.
But for complex views, you may need to create some custom code or shortcodes. Still, all the data/queries, will be simpler:
- A brand active countries: The "Brand active countries" related to the Brand.
- Distributors fo a brand: The "Brand owners" connected to the "Brand active countries" posts that are connected to the Brand.
- etc...
Personally, I would prefer the second option, using an additional custom post type to represent what countries a Brand is active on it. Countries can then be a custom field on this custom post type or taxonomy.
I hope this makes sense. I remain at your disposal.
Hi Jamal
Thanks for the update and the effort.. really appreciate it..:-)..
It's a bit late here in Bali.. almost midnight .. so i'll try it tomorrow morning..
but in the meantime, can you help me with this query so that in the morning I will know what to do?
For now, the checkbox option works well for me.. I am not looking too far ahead.. but it seems to meet my existing requirements.. and from your suggestions even I would have preferred the option to make another custom post type called 'Countries' and assign the brands or brand owner or whichever way you suggested.. BUT at this point if the checkboxes are working fine for me, is there any reason or need for me to take that step?
Is having checkboxes not a very good option? Is it because of performance or complexity or is it not logical? Coz to me knowing that I could have a better method (what you and your team is suggesting) is good for the future but for now, I'd rather stick to the checkbox option UNLESS you feel there's something wrong with it..
Please do advise..
Regards,
Alim
Hello Alim,
BUT at this point if the checkboxes are working fine for me, is there any reason or need for me to take that step?
You decide 🙂 If your current data model suits you. That's fine, just keep it. No need for an additional step, that will for sure add its complexity, and that will probably require you to update other elements of your website(relationships, views, etc.)
Is having checkboxes not a very good option? Is it because of performance or complexity or is it not logical?
Actually, I was mistaken and I thought that a view could not be filtered with a custom field of type "Checkboxes" in comparison to the field type "Checkbox". So I run a test and I was able to filter a view with the Checkboxes field. I can't say it is not a good option.
Regarding performance, it may have a small footprint because of the way checkboxes are saved in the database(serialized array) but I do not think that this performance hit will appear for a small to a medium website, but if you are querying millions of post, it may have a performance hit compared to another data model. Finally, no one can really give performance decisions without having measured the current state of the system in several ways/scenarios.
All the best for you project.
Thanks Jamal..:-)..
Have a nice nice day..:-)..
Regards,
Alim