1

Symfony get relational data: I have ReservedOffer object and i am getting values like $reservedOffer->getOfferGroup()->getOffer()->getGood() i get like see image.enter image description here

But

$reservedOffer->getOfferGroup()->getOffer()->getGood()->getName() // Sony

but in twig if i write

reservedOffer.offerGroup.offer.good.name // i get ''

Why? Any idea?

3
  • what is your query, DQL or querybuilder? Commented Apr 10, 2017 at 7:02
  • Hi @FrankB reservedOffer is a controller action parameter so get directly reservedOffer object. Commented Apr 10, 2017 at 7:03
  • In that case Symfony tries to load the reservedOffer object for you. Might be better to pass the id of the object as parameter and then load it yourself. If you dont understand me then ask me for an example Commented Apr 10, 2017 at 7:56

2 Answers 2

2

So now i am selectindg data of associated tables also and my issue solves. It worked by

public function findReservedOfferWithRelationData(ReservedOffer $reservedOffer)
{
    return $this->createQueryBuilder('reservedOffer')
        ->select('reservedOffer, offerGroup, offer, good')
        ->join('reservedOffer.offerGroup', 'offerGroup')
        ->join('offerGroup.offer', 'offer')
        ->join('offer.good', 'good')
        ->where('reservedOffer.id = :id')
        ->setParameter('id', $reservedOffer->getId())
        ->getQuery()
        ->getOneOrNullResult();
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try to set twig's strict_variables to true and you will see the error

# app/config/config.yml
twig:
    debug:            true
    strict_variables: true

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.