Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9096611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:53:49+00:00 2026-06-16T23:53:49+00:00

I have a bidirectional one-to-many relationship between two classes (Protocol and History). While searching

  • 0

I have a bidirectional one-to-many relationship between two classes (Protocol and History). While searching for a specific Protocol, I’m expected to see all History entries associated with that protocol.

While rendering my template, I pass the following:

return $this->render('FunarbeProtocoloAdminBundle:Protocolo:show.html.twig', array(
        'entity'      => $entity,
        'delete_form' => $deleteForm->createView(),
        'history' => $entity->getHistory(),
    )
);

entity->getHistory() returns a PersistentCollection instead of an array, which causes the following to render an error:

{% for hist in history %}
<tr>
    <td>{{ hist.dtOcorrencia|date('d/m/Y H:i') }}</td>
    <td>{{ hist.dtRetorno|date('d/m/Y H:i') }}</td>
</tr>
{% endfor %}

If instead of $entity->getHistory() I pass $em->getRepository('MyBundle:History')->findByProtocol($entity), it works fine. But I figure the main point of having a bidirectional relationship was to avoid opening repositories and explicitly opening new resultsets.

Am I doing something wrong? How am I supposed to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:53:50+00:00Added an answer on June 16, 2026 at 11:53 pm

    All I had to do was call the following on my TWIG:

    {% for hist in entity.history %}
    

    None of the other answers worked for me. I have to call the property directly in my twig instead of using its getter. Don’t know why, but it worked.

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bi-directional one-to-many relationship defined between Parent and Child classes. I'm looking
i have two Entities, Parent and Child, that are linked through a bidirectional one-to-many
I have a bidirectional one-to-many relationship. I'm trying to persist it like in this
In my domain, an Employee and a Department have a one-to-many bidirectional relationship; to
I have the One-to-Many bidirectional relationship below. After generating the crud actions with a
I've two domain classes which are bonded with a bidirectional one-to-one relationship to each
If I have a relationship between two tables (both tables have their own primary
I have an Class with a unidirectional one to many relationship as follows: public
You create a bidirectional one-to-one relationship using fields on both classes, with an annotation
I have OneToMany bidirectional relationship enity classes ( WorkOrder and Task ). WorkOrder have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.