What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hey Spryks! Can anyone advise on how we do Joins across modules when pulling data? Example… I’ve

U02P7B6K2LC
U02P7B6K2LC Posts: 121 🧑🏻‍🚀 - Cadet

Hey Spryks!

Can anyone advise on how we do Joins across modules when pulling data?

Example…

I’ve set up a module called “Recipes” and also created “RecipeSearch” as module for handling Elastic Search. (I’ve followed the guidance in the Backend Dev Course for this).

Ok so the Recipe table is working and so is elastic search… but each recipe has a list of ingredients. These are on another table with an FK to the recipes table.

What’s best practice for me to pull in this data also? Is there a guide for this?

My approach to this would be to change the RecipeTransfer to reflect the ingredients data, then use the RecipeSearchWriter to pull this data. However, I think I would need to change the RecipeEntity to include the ingredient data … ?

Any help on this would be much appreciated.

Comments

  • UKEP86J66
    UKEP86J66 Posts: 208 🧑🏻‍🚀 - Cadet

    If you want to be fully decoupled you can define a RecipeExpanderPluginInterface inside your recipe module and then implement concrete expander plugins in related modules, like IngredientExpanderPlugin. These plugins will handle populating any extra data for the recipe.

  • UKEP86J66
    UKEP86J66 Posts: 208 🧑🏻‍🚀 - Cadet

    However decoupling comes at the cost of repeated db calls, so if performance is important you should try and compile as much as possible in pub/sync so everything is there ready for your view code.

  • U02P7B6K2LC
    U02P7B6K2LC Posts: 121 🧑🏻‍🚀 - Cadet

    Thank you @UKEP86J66… yes the first option is probably fine, since I’m going to be collecting all the data and sending it to Reddis and Elastic Search… so the extra DB calls are only pre-sync…

    Is there a good pre-built example of an expander plugin interface that I can use to learn from?

  • UKEP86J66
    UKEP86J66 Posts: 208 🧑🏻‍🚀 - Cadet

    Luckily there are plenty in Spryker, I was looking at ViewDataExpanderPluginInterface this morning which made me think of this pattern.

  • UKEP86J66
    UKEP86J66 Posts: 208 🧑🏻‍🚀 - Cadet

    But there are plenty of other examples in Spryker if you search for *ExpanderPlugin* classes. They should, in theory, all follow a similar pattern

  • UKEP86J66
    UKEP86J66 Posts: 208 🧑🏻‍🚀 - Cadet

    You can also decouple any transfer object changes across modules. For example your IngredientExpander might want to populate a ingredients property of RecipeTransfer so you can add this property by extending the transfer inside the Ingredient module. That way if you ever remove the ingredient module it should tidy up after itself 🙂