See documentation:
http://docs.doctrine-project.org/en/latest/reference/annotations-reference.html#manytomany


   - *mappedBy*: This option specifies the property name on the 
   targetEntity that is the owning side of this relation. Its a required 
   attribute for the inverse side of a relationship.
   - *inversedBy*: The inversedBy attribute designates the field in the 
   entity that is the inverse side of the relationship.

So: don't get fooled by the word "mapped" in "mappedBy": it is not about 
the mapping to table-columns, but to the associated entity. Two different 
worlds: your model with entities (which have fields = properties) and the 
tables (which have columns).

You don't have to keep the same names for the entity-fields and for the 
table-column names. With the 'name' option you can map field to another 
column-name. See documentation (options have the same names in a PHP-array 
as with annotations, so see reference for that, like the one I linked to 
above). 

Naming is important: they should be informative. Otherwise you get 
unmaintainable software. You can probably get better names than 'infos' or 
'rem'. If you want to model clients and products, then you better give 
those entities names like Client and Product. If you then say: a client can 
have ordered multiple products, you could give the Client a field 
'orderedProducts', which holds a collection of Product entities (this would 
be a ManyToMany relation, for a product can also be bought by other 
clients). Say a client can also give comments about the products, then we 
have a OneToMany relation; a comment can only be given by one client). Then 
you could make a field $productComments in the Client enity, which holds a 
collection of Comment entities. If you also want the other side of that 
same association in the Comment entity, then you could make a $commentedBy 
property in the Comment-entity, holding the Client-entity that wrote the 
comment. In this case in the OneToMany association of fieldName 
'productComments' the mappedBy option would be 'commentedBy' in the 
targetEntity 'Comment'. 

If you don't have an existing database as a starting point, it mostly is 
best to start with the model: define the entities, their properties and 
behaviour, and the associations between the entities. Then map that model 
to tables.

On Friday, 14 February 2014 20:52:37 UTC+1, Parsifal wrote:
>
>  
> reading wiki, it uses the same name for mappedBy/inversedBy for fieldName, 
> this way I could not understand the difference? they should use the same 
> name always or mappedBy/inversedBy refers to which property? Here is my 
> mapping:
> $metadata->mapOneToMany(array( 'fieldName' => 'infos',
>                                'targetEntity' => 'Entities\\Info',
>                                'mappedBy' => 'infos',
>                                'joinColumns' => array( 0 => array( 'name' 
> => 'product_id',
>                                                                   
>  'referencedColumnName' => 'product_id',
>                                                                   
>  'nullable' => true,
>                                                                   
>  'columnDefinition' => NULL,
>                                                       ), )
>                                 
>                              ));
> I understand fieldName is: "...FROM u.*infos"* but mappedBy name refers 
> to which property?
>  

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