Hello - hoping someone can help with a related items automation… I’ll do my best to explain the architecture.
The premise of the site is a marketplace.
Thing 1 - “Categories”
Each Thing is a different category of item that a user may want to list for sale. Categories need to be their own Thing because each category has a dataset attached to it and a parent relationship. Categories needed to be a Thing - Options were not a viable solution. Categories have a field called “Related Items” that allows for a list of multiple Items.
Thing 2 - Items
Items are individual products that people want to sell. (No inventory.) These items have a status field that indicates whether an Item is “listed” or not. Items have a Category field in the data set so we know where it belongs.
When an Item is marked as “listed” I can’t seem to figure out how to add that Item to its related Category’s Related Items. I’m hoping this is a fairly simple oversight on my part and not a major issue with the data architecture.
Hey @lauren5. Categories have a list of items called related items and Item has a field called category. It sounds like a circular loop where one of them is redundant.
About your question: who changes the listed field of an item? Because that’s the exact place where this thing needs to happen, whem the item is listed, update the item’s category’s related items.
Alternatively, you can add a database trigger: whenever listed field of an item has been updated, you can do the same as above.
I still believe the first option is more feasible.
Yes, they are redundant. I could potentially get rid of the Related Category field on the Item but I’d have to think that through.
This is what it looks like to the user.
User wants to list Items so they browse through a series of nested category filters until they find the Category (aka type) of item they want to list. They click an “Add” button to place those Categories in a cart. When they click “Add” it creates an Item with the status “in cart.”
There is a minimum number of Categories that the user needs to add to the cart in order to advance to the next step. Once that minimum is reached, they can then click a “Next” button to advance to the next step. At that point, the Item status is updated from “in cart” to “listed.” There are other statuses for Items, so basically, any time an Item is not “listed” it would also need to be removed from the relevant Categories list of Related Items.
I think it would be cleanest to make some sort of condition or database trigger that says:
If Item is “listed”, then do a search for Item’s Category and add Item to Category’s list of Related Items.
It seems like that would save me a ton of work building that logic into all of the workflows that manipulate the Item’s status.
Looking more into database triggers, this is the right direction but I’m still stuck.
My trigger is when Item is now “listed” to run an API workflow. That API workflow should be Make Changes to a Thing (Category) and be able to reference the Item that triggered it. @hergin - do you have any idea how I reference that Item here?