THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline

#1 Check null status in Propel

(12-07-2019 09:01:57)


Hello!

I have a small quality of life/code question and it's regarding propel, I tried doing some specific research but couldn't find anything good. We have a lot of imports/data updating operations happening and most of them specific so we end up writing a lot of propel code, I was wondering if there is a way to avoid null checks when trying to retrieve information from db.

ex:
$foundExistingProductI18n = ProductI18nQuery::create()->filterById($foundProduct)->findOneByLocale($locale);
if ($foundExistingProductI18n != null){
$foundExistingProductI18n=$foundExistingProductI18n->getTitle();
}

This is what we do now, I would like to know if there is a propel flag/operation that can be done so that an error isn't thrown and something like this would work without an error.
$foundExistingProductI18n = ProductI18nQuery::create()->filterById($foundProduct)->findOneByLocale($locale)->getTitle();

Thank You!

Offline


Something like this would work :

$title = ProductQuery::create()->findPk($foundProduct)->setLocale($locale)->getTitle();

If title is not defined for $locale, you'll get null (assuming $foundProduct is a valid and existing product ID)


OpenStudio Toulouse