Fetch data from Entity’s to another

Asked

Viewed 52 times

0

I have an Intervention Ntity, a Breakdown and a Forecast One and I wanted to go and eat the data of these Ntity and put it all together in one table.

The table that joins everything will be inside the Intervention Entity within a detail.html file.

Table will be: Intervention: Date, Time and Duration; Malfunction: Date, Description and Impediment; Scheduled: Count, Duration, Make, Time and Record; inserir a descrição da imagem aqui

My chart looks like this: Worker Intervention Breakdown Planned Id Identity Date Time Duration Date Description Deterrent Counting Duration Do Weather Token {% for Entity in entities %} {% if Entity.data %}{{ Entity.data|date('Y-m-d') }}{% endif %} {% if Entity.horainicio %}{{ Entity.horainicio|date('H:i') }}{% endif %} {{ Entity.duracao }} {% endfor %}

How do I get the data from the other Entity to this table?

The relationships between them are: In Intervention:

/**
* @ORM\ManyToOne(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Maquina", inversedBy="intervencao")
* @ORM\JoinColumn(name="maquina_id", referencedColumnName="id", nullable=false)
*/
private $maquina;

In Breakdown:

/**
* @ORM\ManyToOne(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Maquina", inversedBy="avaria")
* @ORM\JoinColumn(name="maquina_id", referencedColumnName="id")
*/
private $maquina;

In Forecasted:

/**
* @ORM\ManyToOne(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Maquina", inversedBy="prevista")
* @ORM\JoinColumn(name="maquina_id", referencedColumnName="id")
*/
private $maquina;

In the Intervencaocontroller:

/**
 * Lists all Intervencao entities.
 *
 * @Route("/", name="manutencao_intervencao")
 * @Method("GET")
 * @Template()
 */
public function indexAction() {
    $em = $this->getDoctrine()->getManager();
    $entities =$em->getRepository('RoqSysControlManutencaoBundle:Intervencao')->findAll();
    $avarias = $em->getRepository('RoqSysControlManutencaoBundle:Avaria')->findAll();
    $previstas = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->findAll();

    return array(
        'entities' => $entities,
        'avarias' => $avarias,
        'previstas' => $previstas,
    );
}
  • What is the relationship that entities (Intervencao, Avaria and Prevista) own with each other? Manytoone, Manytomany, Onetomany, Onetoone etc.

  • Na intevenção: /**
 * @ORM\ManyToOne(targetEntity="RoqSys\Control\ManutencaoBundle\Entity\Maquina", inversedBy="intervencao")
 * @ORM\JoinColumn(name="maquina_id", referencedColumnName="id", nullable=false)
 */
 private $maquina;

2 answers

1

From what I’ve seen in the relationships of your entities, you should do the following.

First search all machines, since all other entities have relationship with it, with the following DQL:

SELECT m, i, a, p
FROM RoqSysManutencaoBundle:Maquina m
LEFT JOIN m.intervencoes i
LEFT JOIN m.avarias a
LEFT JOIN m.previstas p

One problem in this case is that you don’t know how many interventions, malfunctions or predicted a machine has - so you’ll have to draw your table thinking about it.

After you have passed the data to your view, just make a loop external by machines and loops internal to damage, intervention and planning:

{% for maquina in maquinas %}

Intervencoes:<br>
{% for intervencao in maquina.intervencoes %}
    {{ intervencao.data }}<br>
    {{ intervencao.duracao }}<br>
{% endfor %}

Avarias:<br>
{% for avaria in maquina.avarias %}
    {{ avaria.data }}<br>
    {{ avaria.descricao }}<br>
    {{ avaria.impedimento }}<br>
{% endfor %}

Previstas:<br>
{% for prevista in maquina.previstas %}
    {{ prevista.contagem }}<br>
    {{ prevista.duracao }}<br>
    {{ prevista.fazer }}<br>
    {{ prevista.tempo }}<br>
    {{ prevista.ficha }}<br>
{% endfor %}

{% endfor %}

Edit: After your add-on, I saw what you’re doing wrong. You’re bringing the collections of entities like Intervencao, Avaria and Prevista separated from each other and detached from the machines. It is more interesting you bring the machines with the DQL I suggested above and pass them to the view as follows:

/**
 * Lists all Intervencao entities.
 *
 * @Route("/", name="manutencao_intervencao")
 * @Method("GET")
 * @Template()
 */
public function indexAction() {
    $em = $this->getDoctrine()->getManager();
    $maquinas = $em->getRepository('RoqSysControlManutencaoBundle:Maquina')->findAll();

    return array(
        'maquinas' => $maquinas
    );
}
  • I’m not making it.

  • What a mistake you’re making?

  • Method "interventions" for Object "Proxies_CG_\Roqsys Control Manutencaobundle Entity Maquina" does not exist in /var/www/roqsys/src/Roqsys/Control/Manutencaobundle/Resources/views/Intervention/index.html.Twig at line 76 => is this the line {% for intervention in maquina.intervencoes %}

  • The relationships you’ve created between the entities are two-way, right? That is, there is the relationship of the machine to the intervention and vice versa. If yes, you only need to create the methods of the entities with the command app/console doctrine:generate:entities RoqSys. Has already done so?

  • yes, I did it right at the beginning, if there were no entities

  • In fact the command generates the methods of the entities contained in the namespace RoqSys. It is because of the lack of methods that you are having the error you charged above.

  • @Catarinasilvestre complemented the answer.

Show 2 more comments

0


No Intervencaocontrol

 /**
 * Lists all Intervencao entities.
 *
 * @Route("/", name="manutencao_intervencao")
 * @Method("GET")
 * @Template()
 */
public function indexAction() {
    $em = $this->getDoctrine()->getManager();
    $entities =$em->getRepository('RoqSysControlManutencaoBundle:Intervencao')->findAll();
    $avarias = $em->getRepository('RoqSysControlManutencaoBundle:Avaria')->findAll();
    $previstas = $em->getRepository('RoqSysControlManutencaoBundle:Prevista')->findAll();

    return array(
        'entities' => $entities,
        'avarias' => $avarias,
        'previstas' => $previstas,
    );
}

And in Intervencao.php

{% for entity in entities %}{% for avaria in avarias %}{% for prevista in previstas %}
                    <tr>
                        <td></td>
                        <td></td>
                        <td>{% if entity.data %}{{ entity.data|date('Y-m-d') }}{% endif %}</td>
                        <td>{% if entity.horainicio %}{{ entity.horainicio|date('H:i') }}{% endif %}</td>
                        <td>{{ entity.duracao }}</td>
                        <td>{% if avaria.data %}{{ avaria.data|date('Y-m-d') }}{% endif %}</td>
                        <td>{{ avaria.descricao }}</td>
                        <td>{{ avaria.impeditiva }}</td>
                        <td>{{ prevista.contagem }}</td>
                        <td>{{ prevista.duracao }}</td>
                        <td>{{ prevista.fazer }}</td>
                        <td>{{ prevista.tempo }}</td>
                        <td>{{ prevista.ficha }}</td>
                    </tr>
                {% endfor %}{% endfor %}{% endfor %}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.