On Wednesday, 26 February 2014 23:55:55 UTC+1, João Carlos Santa Ana wrote:
can someone tell if this correct.

No, sorry, it is not correct yet. Please reread the documentation and try 
to understand *every *line of code you write. 
It is good that you limited the problem to just one relation to start with, 
the UserIdentity, and left the UserAddress out for a moment. Once you get 
the principle you can add other objects to this User-aggregate.

You are trying to make a User-entity that 'has a' UserIdentity; a OneToOne 
association. Because it is a bidirectional relationship, you must have some 
$userIdentity-field in your User. That field is lacking now. In the 
annotation of that field you define the OneToOne-relationship. At the other 
side, in the UserIdentity-entity you have a $user-field. Not a userIId: 
that is irrelevant for the identity and only necessary as a foreign key in 
the table. In the object UserIdentity you don't have a userID, but a user. 
I would describe that relationship as: a UserIdentity 'belongs to' a User. 
Or: a UserIdentity 'gives more information about' a User.

The $user you have in your UserIdentity is of the type User. Hence:  @ORM\var 
\User, not @var \USARIOS (there is no \USARIOS-class). But you can also 
leave that entire line out, as you are allready defining a targetEntity in 
the association, so we know what type it is. 

BTW:I would take another name for User*Identity*, for it is a bit confusing 
name, as it looks like UserID. You could for instance rename it to 
UserProfile, UserDetails, UserInformation or maybe something more 
informative and precise. This is THE chance to give it a good name, you'll 
get clearer code every time you use those attributes later in your 
application.





On Wednesday, 26 February 2014 23:55:55 UTC+1, João Carlos Santa Ana wrote:
>
> The closest I came to a possible solution can someone tell if this 
> correct. If yes how to query from there?
>
> use Doctrine\ORM\Mapping as ORM;
>
> /**
>  * User
>  *
>  * @ORM\Table(name="USUARIOS")
>  * @ORM\Entity
>  * @ORM\Entity(repositoryClass="Rangos\Entity\UserRepository")
>  */
> class User {
>
>     /**
>      * @var integer $userId
>      * 
>      * @ORM\Column(name="USER_ID", type="integer", nullable=false)
>      * @ORM\Id
>      * @ORM\GeneratedValue(strategy="IDENTITY")
>      * @ORM\OneToOne(targetEntity="Rangos\Entity\UserIdentity")
>      * @ORM\JoinColumns({ 
>      * @ORM\JoinColumn(name="USER_ID", referencedColumnName="USER_I_USER")
>      * })
>      */
>     private $userId;
>
>     /**
>      * @var integer $userEmp
>      *
>      * @ORM\Column(name="USER_EMP", type="integer", nullable=false)
>      */
>     private $userEmp;
> }
>
> use Doctrine\ORM\Mapping as ORM;
>
> /**
>  * UserIdentity
>  *
>  * @ORM\Table(name="USUARIOS_IDENTIDADE")
>  * @ORM\Entity
>  * @ORM\Entity(repositoryClass="Rangos\Entity\UserIdentityRepository")
>  */
> class UserIdentity {
>
>     /**
>      * @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\User", 
> inversedBy="userIdentity")
>      * @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;
>
> }
>
>
>
> Em quarta-feira, 26 de fevereiro de 2014 19h13min45s UTC-3, João Carlos 
> Santa Ana escreveu:
>>
>> class User {
>>
>>     /**
>>      * @var integer $userId
>>      * 
>>      * @ORM\Column(name="USER_ID", type="integer", nullable=false)
>>      * @ORM\Id
>>      * @ORM\GeneratedValue(strategy="IDENTITY")
>>      */
>>     private $userId;
>>
>>      /**
>>      * @ORM\OneToOne(targetEntity="Rangos\Entity\UserIdentity")
>>      * @ORM\JoinColumns({ 
>>      * @ORM\JoinColumn(name="userIdentity", 
>> referencedColumnName="USER_I_USER")
>>      * })
>>      */
>>     private $userIdentity;
>> }
>>
>> class UserIdentity {
>>
>>     /**
>>      * @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\User", 
>> inversedBy="USER_ID")
>>      * @ORM\JoinColumns({ 
>>      * @ORM\JoinColumn(name="USER_I_USER", referencedColumnName="USER_ID")
>>      * })
>>      */
>>     private $userIUser;
>>
>> }
>>
>> PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 
>> 't0.userIdentity' in 'field list'
>>
>> Em quarta-feira, 26 de fevereiro de 2014 18h08min07s UTC-3, Marco Pivetta 
>> escreveu:
>>>
>>>
>>>
>>> On 26 February 2014 21:53, João Carlos Santa Ana 
>>> <[email protected]>wrote:
>>>
>>>> I do not believe to be 4 days to solve this :/. 
>>>> keep getting an exception:
>>>>
>>>> AnnotationException: [Semantical Error] The annotation "@OneToOne" in 
>>>> property Rangos\Entity\User::$userIdentity was never imported. Did you 
>>>> maybe forget to add a "use" statement for this annotation? 
>>>>
>>>>
>>> You need to prefix the annotation with "ORM\", so it should be 
>>> "@ORM\OneToOne"
>>>
>>> Read your exception messages carefully ;-)
>>>
>>> Marco Pivetta 
>>>
>>> http://twitter.com/Ocramius      
>>>
>>> http://ocramius.github.com/ 
>>>  
>>

-- 
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