Jump to content

Many to many with extra field (role/person/article)


joe_g
 Share

Recommended Posts

Hi there,

I'm wondering how to best go about this. I'd like to add a "person" with a "role" to an "article", like

Josh, editor article X
Jane author article X


Jill editor article Y
Jessie photographer article Y
Joan author article Y

etc..

What would be the best way to be able to achieve this without losing the nice, existing API way to find stuff. Like, "Find all articles where Joan is part of", or perhaps "Find all articles Joan is the author of".

Is this possible? I can imagine using FieldTable for this, but I'm not sure how the API looks to find things afterwards.

Link to comment
Share on other sites

Thanks, I think I'm familiar with this. He's describing the standard processwire fields. It's not a hierarchy, rather a 3-way join. In my case I'd like to specify a "role" for each relationship "person" and "article".

It's solvable with a Repeater, for example (a repeater with "person" and "role", for example). The problem with repeaters is that the search queries gets a bit awkward. I've run into problems with searching in repeaters in the past (having to use getForPage() and  check_access=0) so I'm a bit hesitant to use them to store anything that needs to be searched for later on. Unless repeaters have changed under the hood I suppose I will run into the same thing today if I were to look up all "articles associated with a person", for example. So I was hoping there was a better way.

But perhaps repeaters have improved in the mean time?

I did test the FieldtypTable just now, and it works as expected, so that's an okay solution actually

 

 

Link to comment
Share on other sites

Hi @joe_g. How about 3 templates: person, role and article.

Role has 3 fields: title (name of the role) and page ref fields to each of person and article

Person and article have page ref fields to role.

Use ConnectPageFields module - 2 entries for each of the 2 relationships.

Allow new pages to be created when in the page ref fields of person and article templates.

You can then add a new role page when editing person or article, complete with the required linkage.

Use API to get all the role/article combinations for any person etc.

If you want to restrict roles to a list then you could use a select options or even another page ref field, and just put a ref in the title.

 

Link to comment
Share on other sites

@joe_g Why not adding on "article" template 3 fields (PageReference for multiple pages of template "user"), "authors", "photographers", "editors"?

On 11/2/2023 at 12:46 PM, joe_g said:

Find all articles where Joan is part of

 

wire()->pages->find("template=article, authors|photographers|editors=$joan->id");

 

On 11/2/2023 at 12:46 PM, joe_g said:

Find all articles Joan is the author of

 

wire()->pages->find("template=article, authors=$joan->id");

 

Link to comment
Share on other sites

6 hours ago, da² said:

Why not adding on "article" template 3 fields (PageReference for multiple pages of template "user"), "authors", "photographers", "editors"?

That’s probably fine if you don’t want to add other types of relationships dynamically. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...