I'm sorry, but not solved the problem. 
I will show what I need if you can appreciate it with an example.

namespace Rangos\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Usuarios
 *
 * @ORM\Table(name="USUARIOS")
 * @ORM\Entity
 * @ORM\Entity(repositoryClass="Rangos\Entity\UsuariosRepository")
 */
class Usuarios
{
    /**
     * @var integer $userId
     *
     * @ORM\Column(name="USER_ID", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $userId;

    /**
     * @var integer $userEmp
     *
     * @ORM\Column(name="USER_EMP", type="integer", nullable=false)
     */
    private $userEmp;

    /**
     * @var integer $userRest
     *
     * @ORM\Column(name="USER_REST", type="integer", nullable=false)
     */
    private $userRest;
}

namespace Rangos\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * UsuariosIdentidade
 *
 * @ORM\Table(name="USUARIOS_IDENTIDADE")
 * @ORM\Entity
 * @ORM\Entity(repositoryClass="Rangos\Entity\UsuariosIdentidadeRepository")
 */
class UsuariosIdentidade {

    /**
     * @var integer $userIId
     *
     * @ORM\Column(name="USER_I_ID", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $userIId;
   
    
     /**
     * @var \USUARIOS
     * @ORM\GeneratedValue
     * @ORM\OneToOne(targetEntity="Rangos\Entity\Usuarios")
     * @ORM\JoinColumns({
     * @ORM\JoinColumn(name="USER_I_USER", referencedColumnName="USER_ID")
     * })
     */
    private $userIUser;

    /**
     * @var string $userINome
     *
     * @ORM\Column(name="USER_I_NOME", type="string", length=40, 
nullable=false)
     */
    private $userINome;
}

use Doctrine\ORM\Mapping as ORM;

/**
 * UsuariosEndereco
 *
 * @ORM\Table(name="USUARIOS_ENDERECO")
 * @ORM\Entity
 * @ORM\Entity(repositoryClass="Rangos\Entity\UsuariosEnderecoRepository")
 */
class UsuariosEndereco
{
    /**
     * @var integer $userEndId
     *
     * @ORM\Column(name="USER_END_ID", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $userEndId;
    
         /**
     * @var \USUARIOS
     * @ORM\GeneratedValue
     * @ORM\OneToOne(targetEntity="Rangos\Entity\Usuarios")
     * @ORM\JoinColumns({
     * @ORM\JoinColumn(name="USER_END_USER", referencedColumnName="USER_ID")
     * })
     */
    private $userEndUser;

    /**
     * @var integer $userEndBairro
     *
     * @ORM\Column(name="USER_END_BAIRRO", type="integer", nullable=true)
     */
    private $userEndBairro;
}
*I need a query that brings the 3 tables*

Hope you can help.





Em segunda-feira, 24 de fevereiro de 2014 17h04min16s UTC-3, Herman Peeren 
escreveu:
>
> Please look at the documentation about *associations *and about *DQL*.
> Especially: 
> http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#joins
>
> *First *you define your entities. for instance: Usario, UsarioEndereco 
> and UsarioIdentidade (which would be something like: User, UserAddress and 
> UserProfile, if you would say it in English, which is not necessary at 
> all). Mind I used it in singular (Usario), although in your tables you use 
> plural. An entity is a singular thing. You can use different names for the 
> tables and for the entities: you have to map them anyway. 
>
> *Second *you define the associated fields and the mapping. For instance 
> in your Usario entity you can have a $enderecos-field, holding a collection 
> of addresses, with a OneToMany-mapping to your UsarioEndereco entity. And 
> let's say the UsarioIdentidade has a OneToOne association to Usario, using 
> a field $usario in UsarioIdentidade and a field $identidade in Usario.
>
> *Third*, the query. that would then be something like:
>
> $query->select('i','u', 'e')
>                 ->from('Rangos\Entity\usuariosIdentidade','i')
>                 ->join("i.usario", 'u' )
>                 ->join("u.enderecos", 'e')
>
> Or is the Usario used as parent-entity? In that case read the 
> documentation about inheritance:
>
> http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html
>
> Most important: you are not querying the tables with DQL, but the 
> entities! The entities (objects) form a network, the object graph. You can 
> "walk" that graph. The associations are not defined in the query (with ON 
> or WHERE), but in the mapping. That is the whole point of an ORM; otherwise 
> there is no need to use it and you could better just directly query the 
> database with SQL.
>
>
>
> On Monday, 24 February 2014 20:20:12 UTC+1, João Carlos Santa Ana wrote:
>>
>>         $query = $this->getEntityManager()->createQueryBuilder(); 
>>         $query->select('i','u', 'e')
>>                 ->from('Rangos\Entity\usuariosIdentidade','i')
>>                 ->innerJoin("i.userIUser", 'u')
>>                 ->join("Rangos\Entity\UsuariosEndereco", 'e')
>>                 ->where("e.userEndUser", 'u.userId');
>>                  $result = $query->getQuery()->execute();
>>
>> Em segunda-feira, 24 de fevereiro de 2014 16h19min12s UTC-3, João Carlos 
>> Santa Ana escreveu:
>>>
>>> OK, excuse my bad english. 
>>> But I need to bring several tables 1,2,3,4 with reference to a table. 
>>> Where tables 1,2,3,4 contains id of the reference table. 
>>> In DTL consulting encontri not this formula. can help an example? 
>>> thank you
>>>
>>> Em segunda-feira, 24 de fevereiro de 2014 15h57min44s UTC-3, Herman 
>>> Peeren escreveu:
>>>>
>>>> This mailing list is in English. Obrigado!
>>>>
>>>> What you are doing wrong here is: defining an ON-clause. That is how 
>>>> you'd do it in SQL. In DQL however you define the relationship between 
>>>> your 
>>>> entities in the mapping-information (via annotations, xml, yaml or php) 
>>>> and 
>>>> in the query you use that relationship. So: define a OneToOne, OneToMany, 
>>>> ManyToOne or ManyToMany relationship and use that in the query (and 
>>>> consequently no need to use a ON).
>>>>
>>>>
>>>> On Monday, 24 February 2014 19:46:41 UTC+1, João Carlos Santa Ana wrote:
>>>>>
>>>>> Alguém ajuda por favor.
>>>>>
>>>>> Tenho varias tabelas: endereco, identidade, cartao, contato, debitos 
>>>>> ....
>>>>> Todas com o id da tabela do usuario.
>>>>>
>>>>> preciso fazer uma consulta que traga todas as tabelas relacionadas de 
>>>>> uma vez.
>>>>>
>>>>> Tentei fazer uma consulta simples:
>>>>>
>>>>> $query = $this->em->createQuery("SELECT i, e FROM 
>>>>> R\Entity\UsuariosIdentidade as i "
>>>>>                    . " JOIN R\Entity\UsuariosEndereco as e ON 
>>>>> e.userEndUser = i.userIUser ");
>>>>>           $result = $query->getResult();
>>>>>
>>>>> Recebo este erro:
>>>>> OBS: SILEX
>>>>>
>>>>> QueryException: [Semantical Error] line 0, col 92 near 'as e ON 
>>>>> e.userEndUser': Error: Identification Variable R\Entity\UsuariosEndereco 
>>>>> used in join path expression but was not defined before.
>>>>>
>>>>> Alguem pode dar alguma direção do que devo fazer para conseguir uma 
>>>>> query que me traga todas as tabela seja com createQueryBuilder, 
>>>>> createQuery 
>>>>> ou  EntityRepository;
>>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to