This looks correct :)

Please remember that in this case there is _no_ direct association between 
Person and Company, as the relationship is established through Job.

If you like you can add a proxy method to fetch all Companies from a Person:

    class Person
    {
        // ...

        public function getCompanies()
        {
            return array_map(
                function ($job) {
                    return $job->getCompany();
                },
                $this->jobs
            );
        }

-- 
Jasper N. Brouwer
(@jaspernbrouwer)


On 7 Jan 2014, at 15:15, Sandro Cândido <[email protected]> wrote:

> Hi
> 
> Below is a template to create annotation and database, in this model to 
> perform the job CLI php doctrine orm:generate-entities /var/www/project 
> --generate-annotations=true after php doctrine orm:schema-tool:create you'll 
> see that the job does not add table relationship with the company table. I 
> need a many to many relationship with the job table that is has the extra 
> columns
> 
> YAML:
> 
> person\models\entities\Person:
>     type: entity
>     repositoryClass: person\models\entities\PersonRepository
>     table: person
>     indexes:
>         name_person_index:
>             columns: [ name ]
>     fields:
>         id:
>             id: true
>             type: integer
>             generator:
>                 strategy: IDENTITY
>         name:
>             type: string
>             length: 200
>             nullable: false
>         birth_date:
>             type: date
>             nullable: false
>         email:
>             type: string
>             length: 80
>             nullable: true
>         username:
>             type: string
>             length: 60
>             nullable: false
>         password:
>             type: string
>             length: 64
>             nullable: false
>     oneToMany:
>         jobs:
>             targetEntity: person\models\entities\Job
>             mappedBy: person\models\entities\Person
>             cascade: ["persist", "merge"]
> 
> ------------------------------------------------------------------------------------------------------------
> person\models\entities\Job:
>     type: entity
>     repositoryClass: person\models\entities\JobRepository
>     table: job
>     fields:
>         id:
>             id: true
>             type: integer
>             generator:
>                 strategy: IDENTITY
>         begin_salary:
>             type: integer
>             nullable: false
>         monthly_salary:
>             type: integer
>             nullable: false
>         begin_job_date:
>             type: date
>             nullable: false
>         resignation_date:
>             type: date
>             nullable: false
>     manyToOne:
>         company:
>             targetEntity: person\models\entities\Company
>             joinColumn:
>                 name: company_id
>                 referencedColumnName: id
>     manyToOne:
>         company:
>             targetEntity: person\models\entities\Person
>             joinColumn:
>                 name: person_id
>                 referencedColumnName: id
> 
> --------------------------------------------------------------------------------------------------------
> 
> person\models\entities\Company:
>     type: entity
>     repositoryClass: person\models\entities\CompanyRepository
>     table: company
>     indexes:
>         name_company_index:
>             columns: [ name ]
>     fields:
>         id:
>             id: true
>             type: integer
>             generator:
>                 strategy: IDENTITY
>         name:
>             type: string
>             length: 200
>             nullable: false
>         description:
>             type: text
>             nullable: false
>     oneToMany:
>         jobs:
>             targetEntity: person\models\entities\Job
>             mappedBy: person\models\entities\Person
>             cascade: ["persist", "merge"]
> 
> Em terça-feira, 7 de janeiro de 2014 06h14min34s UTC-2, Jàπ (Jasper N. 
> Brouwer) escreveu:
> Hi Sandro, 
> 
> My blog posts describe how to manage such a use-case, but uses annotations to 
> keep it simple. 
> 
> You can have a look at the docs [1] and yaml driver [2] to translate the 
> annotations to yaml. 
> 
> [1]: http://docs.doctrine-project.org/en/latest/reference/yaml-mapping.html 
> [2]: 
> https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
>  
> 
> -- 
> Jasper N. Brouwer 
> (@jaspernbrouwer) 

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