Welcome to the THELIA support and discusssion forum


Rejoignez la communauté sur le Discord Thelia :


#1 Check null status in Propel

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


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.

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

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!


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