Skip Navigation

[Resolved] Post-relationship Testing

This support ticket is created 6 years, 6 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.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 7 replies, has 3 voices.

Last updated by Beda 6 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#576730

I've been using Toolset for many years, including on my own site. The post-relationship feature is what I've been waiting for to make my site do everything I want it to—so I'm excited about the coming release! However, it seems that it doesn't quite work the way I expected. I've installed the new beta and created some types, relationships, and sample content.

I am an artist, and I have custom post types for my paintings ("works") and for the galleries that I work with ("dealers"). Galleries sell artwork on consignment. So I might send 6 paintings to a gallery, and they will try to sell them. Any work that they don't sell will eventually be returned to me, and may then be consigned to a different gallery.

(As an aside, it would be really convenient for me if I could create a relationship between a custom post type and users, but I gather that is not possible. Not a big problem as I can use my custom type "dealer" instead, but there would be advantages to using the Users.)

So I created two types of relationships between "works" and "dealers." The relationships are called "consignments" and "sales." Consignments are many-to-many, for obvious reasons. Sales should theoretically be one-to-many, since only one dealer will sell a given painting. However, if I create that relationship as one-to-many, I am not allowed to connect a painting to a dealer (via the "sales" post type) if that painting is already connected to the dealer through the "consignment" post type. So I changed "sales" to a many-to-many relationship, and then was able to connect it.

The main thing that I was surprised by was the inability to connect multiple posts to another post type via a single relationship instance. For example, I thought I would be able to create a single "consignment" or "sale" that would connect multiple paintings to a gallery. One of my galleries just made a large sale of 12 paintings. So I'd like to be able to create a single "sale" for that, with relationship fields of "sale date" and "sale notes" so I could just enter the date and my notes about the sale one time for all 12, rather than doing it for each of the paintings. This is not possible, right?

I was hoping to use the post-relationship to generate consignment sheets (packing lists) for when I ship artwork. I was thinking that I'd be able to create a view that displays a single "consignment" of several paintings. This would show the gallery name, address, etc. (from the "dealer" post type) at the top of the page along with the consignment date (a field belonging to the relationship). Below that would be a list of the paintings belonging to this consignment, one per line, showing title, medium, size, price, etc. But since each painting is a separate consignment (unless I'm misunderstanding things), maybe the view could filter by consignment date to capture all the correct paintings?

One other general question: is it possible to control which field columns are displayed in the relationships that are listed on a post's edit page? For example, when I connect a painting to a dealer, there are many columns showing data I don't need to see in that context.

Thanks for your help and for developing the post-relationship feature—a lot of people will be happy about it.

#576803

Let me reply first to the Questions I can answer straight forward

As an aside, it would be really convenient for me if I could create a relationship between a custom post type and users, but I gather that is not possible. Not a big problem as I can use my custom type "dealer" instead, but there would be advantages to using the Users.

Yes, we are aware of this. A feature Request is filed to make it easier to connect Users to Post Types.
But I cannot state any ETA for this.

One other general question: is it possible to control which field columns are displayed in the relationships that are listed on a post's edit page? For example, when I connect a painting to a dealer, there are many columns showing data I don't need to see in that context.

Not right now, but it will be possible, in the stable releases.
Just as it is possible right now with the stable release to choose what fields to display in the Child relationship table.

Now let me reply to your setup.
I tried to replicate it and at the moment of "Sales should theoretically be one-to-many, since only one dealer will sell a given painting".
Should this not be a One To One relation?
One Painting can be sold to one Dealer only. Hence, it cannot have 2 or more Dealer relations.

But you are right, you cannot assign the same Post to the same Post in a second relationship.
This means if the Dealer is already used in the first relation you cannot use it in the second relation.

I am not exactly sure why this is. Actually, we have an intermediary Post type and that is unique, hence we can identify the relation.
I am adding a Developer here to give light in this.

You can very well connect several Posts to a single deal Post.
This is exactly what the Many to Many relation is for.
But you would need to let's say, create a Deal post, and in the relationship table at the bottom of the edit interface, you choose all the posts that belong to this sale (paintings).
Does this help?

You can also add Fields to all the Post Types, even to the intermediary post Type, if this is needed.
But in your case, I do not see the need for such complex setups.

It should be enough to connect the Paintings to many Dealers (Many To Many) and the sales, should be a one to one relation.
But there we have that conflict mentioned above, let's see what the developer means!

#576924
edit-consignment.jpg
add-work-to-dealer.jpg

Thanks for your reply. There are still a few things I don't understand...

You said "I tried to replicate it and at the moment of "Sales should theoretically be one-to-many, since only one dealer will sell a given painting. Should this not be a One To One relation? One Painting can be sold to one Dealer only. Hence, it cannot have 2 or more Dealer relations."

I think it should be one-to-many, as a painting can only be sold by one dealer, but a dealer can sell many paintings. Right?

You said "You can very well connect several Posts to a single deal Post. This is exactly what the Many to Many relation is for. But you would need to let's say, create a Deal post, and in the relationship table at the bottom of the edit interface, you choose all the posts that belong to this sale (paintings)."

The "deal" post you are referring to sounds like what I currently have set up as an intermediary post called "sale," which is the relationship between the Dealer post type and the Work post type (paintings). But I don't see anywhere that I can add multiple paintings to one sale. When editing the Dealer, and adding Sales to it, I can only select one Work (see screenshot), and when editing a Sale, I don't even see a listing of the posts that this intermediary post is connecting (screenshot shows Consignments edit screen, but Sales looks the same).

#577851

Hello Clay,

I’m Mohammed: the Toolset support team leader. I’ll give my best to help you.

I think that we are close to the solution here.

I think it would be a one-t-many relationship.let me clarify why:
The reason is that the paintings could be sold to only (one) dealer.So, one dealer can buy (many) paintings.

It will be ok also to make it many-to-many if you decided to have "Sales" intermediary custom post type.there will be no issues with that.

But this depends on how you prefer to construct the relationship.
The question here is: Do you prefer the relationship to force you to have the only dealer for the painting or not?

In the one-to-many , when the dealer returns the paintings back to you, you can remove the dealer from the relationship and assign another dealer again if another dealer bought the paintings.but, you can't assign more than one dealer to a painting

In the many-to-many, you may have more than the dealer for a single painting which is not accepted in your model.

==============
If you want to record your sales, I would recommend you to construct two one-to-many relationships
You have paintings sold to a dealer recorded in a sale.
The relationships will be like the following:
(One-to-many) => One dealer can do many sales
(One-to-many) => One sale can contain many paintings

Why the relation is like that? because there is a possibility that the dealer returns painting(s) back to you again. so, there will be no way to track this easier that the previous way.

So, when you got a confirmation that you got a sale, you can create a sale post, add the information you need to the sale, connect it to the painting that were sold and connect it to the dealer. all this in a single screen(the sale post edit screen)

==============
Let me clarify something about the many-to-many relationships.
Taking your model as an example, we have paintings and dealers in a many-to-many relationship.

You should have an intermediary custom post type but you don't connect anything to it, you may even hide it.
So, You connect the paintings with the dealers and the intermediary posts should be created behind the scenes.
And, in the dealer edit screen, you should be able to add many paintings. And in the painting edit screen, you should be able to add many dealers.

If you already constructed your relationship to be like this example and you have an issue in connecting paintings with dealers, then there are two possibilities here.
The first one is that you did something wrong while creating the relationship. I can help you in that if you want.
The second is that we have an issue or there is some bug or a conflict.in this case, I will be thankful if you provided access credentials to a test website in where the issue is replicated.

For that, I will set the next reply as a private one so that you can provide the credentials securely.

Thanks.

#578879
2 one-to-many rels.jpg

Mohammed,

Thank you for your help. Let me get some clarification on a couple of things:

When you said:
"If you want to record your sales, I would recommend you to construct two one-to-many relationships
You have paintings sold to a dealer recorded in a sale.
The relationships will be like the following:
(One-to-many) => One dealer can do many sales
(One-to-many) => One sale can contain many paintings"

I think we are on the same page here, but I'm attaching a diagram below to make sure. I think you are suggesting that the "sale" post type would be a regular post type (not an intermediary post type), right? So the two one-to-many relationships would be "dealer > sales" and "sale > paintings"?

You said:
"You should have an intermediary custom post type but you don't connect anything to it, you may even hide it.
So, You connect the paintings with the dealers and the intermediary posts should be created behind the scenes.
And, in the dealer edit screen, you should be able to add many paintings. And in the painting edit screen, you should be able to add many dealers."

This is what I was trying to do, but I thought that a single intermediary post (sale) could connect multiple paintings to a single dealer. But it seems that each painting that I connect to a dealer creates an intermediary post, correct? It doesn't really matter to me whether the post type is intermediary or regular, but I need to have a single post (sale) that can connect more than one painting to a dealer, because I want to be able to display a single "sale" that will show all the paintings that were sold in that particular transaction. I think that creating a "sale" post type (not intermediary), like you suggest above, will be the solution.

I hope this is clear. If not, please let me know, and I will try to explain it better.

#579290

I think we are on the same page here, but I'm attaching a diagram below to make sure. I think you are suggesting that the "sale" post type would be a regular post type (not an intermediary post type), right?

Yes.

And, in the dealer edit screen, you should be able to add many paintings. And in the painting edit screen, you should be able to add many dealers."

This is when you go with the many to many relation, which is not needed in the above described schema.

But it seems that each painting that I connect to a dealer creates an intermediary post, correct?

Yes - but only if you choose an intermediary post type in a many to many relation.

For your particular need, I think Mohammeds solution is brilliant because it also allows you to query all 3 types of data, just in case you need to display it.

Please let me know if you would like to share further feedback about the new Many to Many features or have any more follow up questions!

#579697

Thanks Beda. It's clear to me now how I should set things up for my particular situation. In the interest of maybe saving someone else some time or frustration, I'll clarify a couple of things that I did not understand before. Maybe these things are already in the documentation, and I missed them, or maybe they should be added to the documentation. And, of course, correct me if I'm wrong about these things:

1) If post type A and post type B are connected via a relationship (with intermediary post type C), then each post of type C connects one A to one B. It cannot connect one A to multiple Bs or vice versa. If the relationship is one-to-many or many-to-many, then multiple Bs can be connected to a single A, but not through a single C. A separate post of type C will be created for each B that is connected to that single A. And...

2) Intermediary posts cannot be queried or displayed on the front end.

I think my one remaining question is, What are the benefits of creating an intermediary post type?

Thanks for your help.

#579763

1) If post type A and post type B are connected via a relationship (with intermediary post type C), then each post of type C connects one A to one B. It cannot connect one A to multiple Bs or vice versa. If the relationship is one-to-many or many-to-many, then multiple Bs can be connected to a single A, but not through a single C. A separate post of type C will be created for each B that is connected to that single A. And...

If you create an Intermediary Post Type, you will use it to connect each of those Posts to each one parent and eventually every Childs.
But - if you where to create 2 posts types, and connect them all as many to many within each other, you would have the same (an intermediary post type) and since you set the connections manually, you could have a many to many within a "intermediary" post type.

The old method of intermediary post types allowed only one parent a time, instead.

With the new method, intermediary post types are barely needed anymore. But we left it there as it can be useful sometimes.

Intermediary posts cannot be queried or displayed on the front end.

They can be queried. This was how until now you displayed parent data. Usually you queried the intermediary post type or the grandchild and thru the intermediary, the parent data.

Intermediary post types are just like other Post Types.

In the new relationship methods, usually the intermediary post is not shown as not needed anymore, but you can (as in the GUI process of setting up relationships) still choose to show it so to manipulate or query it directly.

I hope it's clear!
Please do not hesitate to ask in case of doubts 🙂

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