Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine override relation accessor
    primarykey
    data
    text
    <p>Say you have the following relations (altered for simplicity):</p> <pre><code>Dog: columns: id: { type: integer, notnull: true, primary: true } name: { type: string, notnull: true } AwardType: columns: id: { type: integer, notnull: true, primary: true } name: { type: string, notnull: true } Award: columns: dog_id: { type: integer, notnull: true, primary: true } award_id: { type: integer, notnull: true, primary: true } is_granted: { type: boolean, notnull: true, default: false } relations: Dog: local: dog_id foreign: id type: one foreignType: many foreignAlias: Awards AwardType: local: award_id foreign: id type: one foreignType: many foreignAlias: Awards </code></pre> <p>With the above setup I can add a new dog and manually add Awards to that dog. I can also edit awards already granted to a dog.</p> <p>When I call $myDog->getAwards() I want the set to include all granted awards (Award.is_granted==true &amp;&amp; Award.dog_id==$myDog()->getId()) pluss all awards that have not been granted to that dog yet.</p> <p>Is there an option that can be set in a model somewhere to make this happen? If not, what would be the best way to achieve it?</p> <p>I'm using Symfony 1.4 and the bundled Doctrine 1.2 ORM. </p> <p>[ Edit 1 ]<br> I realize I didn't explain the whole award thing properly, so I'll try to expand on it. Say you have the following AwardTypes:</p> <ul> <li>1: Bone for not molesting postman</li> <li>2: Collar for not biting Miss Molly</li> <li>3: Bigger bone for chasing milkman (who we all know is evil)</li> </ul> <p>Dog1 is already registered and has been granted AwardTypes 1 and 3. When editing that Dog the form should display AwardTypes 1 and 3 with a checked checkbox and AwardType 2 with an unchecked checkbox. This works great if Dog 1 has one entry in the Award table for each of the AwardTypes. Two with is_granted == true and one is_granted == false. So far so good.</p> <p>When the user enters a new Dog the form should display all the AwardTypes, but with no checked checkboxes. When saving the new Dog a total of 3 rows should appear in the Awards table with the is_granted-flag set according to the checked-state of the checkboxes.</p> <p>I know I can get all AwardTypes and check that against the AwardTypes a Dog has been granted already (showing all unchecked for new dogs, granted checked + not yet granted unchecked for existing dogs). What I am asking here is wether or not Doctrine has some magic that will give me compound sets as described above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload