joe_g Posted November 2, 2023 Share Posted November 2, 2023 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 More sharing options...
ottogal Posted November 2, 2023 Share Posted November 2, 2023 Hi joe_g, I'd recommend to read this fine tutorial written by kongondo a few years ago: Tutorial: Approaches to categorising site content That's the right "PW way" doing it, profiting from the great API. Good luck! ottogal 1 Link to comment Share on other sites More sharing options...
joe_g Posted November 2, 2023 Author Share Posted November 2, 2023 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 More sharing options...
ottogal Posted November 2, 2023 Share Posted November 2, 2023 I never used repeaters, so can't help here... Link to comment Share on other sites More sharing options...
MarkE Posted November 2, 2023 Share Posted November 2, 2023 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 More sharing options...
joe_g Posted November 3, 2023 Author Share Posted November 3, 2023 Ooooo ConnectPageFields, interesting! It de-normalizes/duplicates the data model, feels like it could lead to inconsistencies perhaps? But maybe it's worth that small risk. thanks! Link to comment Share on other sites More sharing options...
da² Posted November 3, 2023 Share Posted November 3, 2023 @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 More sharing options...
MarkE Posted November 3, 2023 Share Posted November 3, 2023 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 More sharing options...
joe_g Posted November 10, 2023 Author Share Posted November 10, 2023 Yes, the roles need to be added dynamically. Link to comment Share on other sites More sharing options...
da² Posted November 10, 2023 Share Posted November 10, 2023 @joe_g What do you mean by adding roles dynamically? $page->authors->add($john); Link to comment Share on other sites More sharing options...
MarkE Posted November 11, 2023 Share Posted November 11, 2023 17 hours ago, da² said: adding roles dynamically? @da² What I meant was being able to add them interactively in the back end Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now