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..

Hi all (again)… to follow on from this… I’ve got the FK tables all set, working and I’ve created al

U02P7B6K2LC
U02P7B6K2LC Posts: 121 🧑🏻‍🚀 - Cadet
edited April 2022 in Help

Hi all (again)… to follow on from this…

I’ve got the FK tables all set, working and I’ve created all the transfers required.

I’m now at the point where I’m trying to pull all the data together to place in the “search” table for elastic search.

So I have a RecipeSearchWriter.php file and I’ve got those rows populating.

So to pull in the Ingredients data from the linked table, I’m using this code:

$ingredients = PyzIngredientQuery::create()->findByFkRecipeId($recipeTransfer->getIdRecipe());
$recipeTransfer->setIngredients($ingredients);

But I’m not able to retrieve any ingredients via the PyzIngredientQuery. I’ve tried:

$ingredientEntities = PyzIngredientQuery::create()->findByFkRecipeId($recipeTransfer->getIdRecipe());

and:

$ingredientEntities = PyzIngredientQuery::create()->filterByFkRecipeId($recipeTransfer->getIdRecipe())->find();

…neither of which are pulling any ingredient data.

When I hardcode the data:

$recipeTransfer->setIngredients('HELLO!');

“HELLO!” does get placed in the Search table - so I’m sure that “setIngredients” works.

Comments

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

    Running

    $ingredientEntities = PyzIngredientQuery::create()->filterByFkRecipeId($recipeTransfer->getIdRecipe())->find();
    

    will return a propel collection, which could look empty depending on what you are doing with it. Usually these collections are iterated using foreach and then each entity is converted to a transfer or scalars and then used.
    To see what is happening you could do something like

    $ingredientEntities = PyzIngredientQuery::create()->filterByFkRecipeId($recipeTransfer->getIdRecipe())->find();
    
    foreach ($ingredientEntities as $ingredientEntity) {
      dump($ingredientEntity->toArray();
    }
    
  • U02P7B6K2LC
    U02P7B6K2LC Posts: 121 🧑🏻‍🚀 - Cadet

    Yes that’s got it! 🙂

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

    Thank you!

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

    Nice, glad it’s working 🙂