Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony Generator Forms, Doctrine, and M:N Relationships
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/6309345/symfony-generator-forms-doctrine-and-mn-relationships">Symfony Generator Forms, Doctrine, and M:N Relationships</a> </p> </blockquote> <p>I have a basic M:N setup with three tables: candidate, position, and candidate_position. Here's my best stab at a crow's-foot style ERD with just text</p> <pre><code>[candiate]-||------|&lt;[candidate_position]&gt;|------||-[position] </code></pre> <p>What I'm trying to accomplish is this: When a <code>candidate</code> is being created or edited, the form will include a checkbox array of all available positions to assign to the candidate.</p> <p>In the normal world of web app development, this is really, really easy. But I'm trying to increase my competency with symfony's admin generator. Here's what I've got so far</p> <p><strong>apps/backend/modules/condidate/config/generator.yml</strong></p> <pre><code>generator: class: sfDoctrineGenerator param: model_class: Candidate theme: admin non_verbose_templates: true with_show: false singular: ~ plural: ~ route_prefix: candidate with_doctrine_route: true actions_base_class: sfActions config: actions: ~ fields: first_name: { label: First Name } last_name: { label: Last Name } created_at: { label: Created On } positions: {} list: sort: [last_name, asc] filter: ~ form: display: "User": [first_name, last_name] "Applying For": [positions] fields : hide: [created_at] edit: ~ new: ~ </code></pre> <p><strong>lib/form/doctrine/candidateForm.class.php</strong></p> <pre><code>class candidateForm extends BasecandidateForm { public function configure() { unset( $this['created_at'] ); $this-&gt;widgetSchema['positions'] = new sfWidgetFormDoctrineChoice( array( 'multiple' =&gt; true, 'model' =&gt; 'Position', 'renderer_class' =&gt; 'sfWidgetFormSelectCheckbox' ) ); $this-&gt;validatorSchema['positions'] = new sfValidatorDoctrineChoice( array( 'multiple' =&gt; true, 'model' =&gt; 'Position', 'min' =&gt; 1 ) ); } } </code></pre> <p><strong>config/doctrine/schema.yml</strong></p> <pre><code>candidate: columns: id: type: integer(4) primary: true unsigned: true notnull: true autoincrement: true first_name: type: string(45) notnull: true last_name: type: string(45) notnull: true created_at: type: integer(4) unsigned: true position: columns: id: type: integer(4) primary: true unsigned: true notnull: true autoincrement: true name: type: string(45) candidatePosition: tableName: candidate_position columns: candidate_id: type: integer(4) primary: true unsigned: true notnull: true position_id: type: integer(4) primary: true unsigned: true notnull: true relations: candidate: class: candidate local: candidate_id foreign: id foreignAlias: candidate_positions position: class: position local: position_id foreign: id foreignAlias: candidate_positions indexes: fk_candidate_position_candidate1: fields: [candidate_id] fk_candidate_position_position1: fields: [position_id] </code></pre> <p>And this works! Sort of =/</p> <p>The checkboxes render to the create and edit screens, but the data doesn't save. Clearly (?) I need to do some customizaton to the model (lib/model/doctrine/candidate.class.php), and that's where I'm losing focus. I'm not sure how to get at the candidate[positions] data from within <code>candidate::save()</code></p> <ul> <li>PHP 5.2.x</li> <li>symfony 1.4.3</li> </ul>
    singulars
    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.
 

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