Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony/propel form saving an object with additional properties
    primarykey
    data
    text
    <p>First, let me say, that I find the sfFormPropel form's interface inconsistent. There is <code>bind()</code>, which returns nothing, but triggers validation, <code>save()</code> which returns the saved object, and <code>bindAndSave()</code>, which returns boolean, actually the return value of <code>isValid()</code>. Now, I have a working application, but I don't feel the code is right, and I'm quite new to <code>symfony</code>, so perhaps I'm missing something.</p> <p>The object I need to create needs some external properties, that are not presented in the form, are external to the model, and are handled by the application (for example, the userId of the user, that created the entity, an external-generated guid, etc.). </p> <p>Right now the flow is as follows:</p> <ul> <li>get values from request and bind them to form</li> <li>check if form is valid</li> <li>if it's valid, add additional values and bind them to form one more time</li> <li>save the form and return the object</li> </ul> <p>The obvious answer would to add application-specific values to the values, retrieved from request, but <em>It does not make sense to bind the application-specific values if the form is not valid, since they can be potentially expensive operations, may create database records, etc.</em> Additionally, it should not be possible to pass those values with the post request, they should come from application only.</p> <p>Now, I though that I have to let the model do these things, but since the data is external to the model, action still need to pass it to the model. The problem is, if I call <code>$form-&gt;getObject()</code> after <code>bind()</code>, it still has the old data, and not the data submitted.</p> <p>What is the correct way to implement this kind of post-processing?</p> <p><em>Second bounty is started to award the other valuable answer</em></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