Note that there are some explanatory texts on larger screens.

plurals
  1. POSave many-to-many in form manually
    primarykey
    data
    text
    <p>I have a model with 3 tables Many to 1 to many as below</p> <p>(shortened schema.yml)</p> <pre><code>PeerEngagement: columns: id: { type: integer(4), notnull: true, unique: true, primary: true, autoincrement: true } peer_id: { type: integer(4), notnull: true } relations: Peer: { local: peer_id, class: Person } Person: columns: id: { type: integer(4), notnull: true, unique: true, primary: true, autoincrement: true } nhi: { type: string(7) } name: { type: string(100), notnull: true } relations: Ethnicity: { class: Ethnicity, refClass: PersonEthnicity, local: person_id, foreign: ethnicity_id } PersonEthnicity: columns: id: { type: integer(4), notnull: true, unique: true, primary: true, autoincrement: true } person_id: { type: integer(4), notnull: true } ethnicity_id: { type: integer(4), notnull: true } relations: Person: class: Person local: person_id onDelete: CASCADE Ethnicity: class: Ethnicity local: ethnicity_id onDelete: RESTRICT Ethnicity: columns: id: { type: integer(4), notnull: true, unique: true, primary: true, autoincrement: true } name: { type: string(50) } </code></pre> <p>Saving these things in auto-generated forms is fine. However in a special case I need to save nhi and ethnicity separately from within PeerEngagementForm.</p> <p>For saving nhi i have working:</p> <pre><code>function doSave($con=null){ ... if(isset($this-&gt;values['nhi'])){ $this-&gt;getObject()-&gt;getPeer()-&gt;setNhi($this-&gt;values['nhi']); $this-&gt;getObject()-&gt;getPeer()-&gt;save(); } ... </code></pre> <p>but the same technique doesn't work with</p> <pre><code>if(isset($this-&gt;values['ethnicity_list'])){ $this-&gt;getObject()-&gt;getPeer()-&gt;setEthnicity($this-&gt;values['ethnicity_list']); $this-&gt;getObject()-&gt;getPeer()-&gt;save(); } </code></pre> <p>The error message I get is that it expects a Doctrine_Collection.</p> <p>How do I create this collection correctly, or how can I save the many to many relationship from within the top form or action?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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