-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add documentation for using DTOs in form handling #10588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Use correct generated code for the DTO. Fix diff indenting. Specify DateType field.
Fix naming of Maker and Data Transfer Objects. Replace ... placeholders with comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @yceruto!
Updated with the changes.
The diff is against the Task entity that would originate from following the forms main library including the validation section.
This was replaced by using @Assert\Type(DateTime) annotation. Related to: symfony/symfony#29029
Build fails due to this commit @javiereguiluz c35b930#diff-f7bfae99d3f5b1553a7bb226b57d1d91 |
form/data_transfer_objects.rst
Outdated
When the validation fails, the invalid data is still left in the entity. | ||
This can lead to invalid data being saved in the database. | ||
|
||
You will use the Maker bundle to highlight the differences between using DTOs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You
should maybe be We
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In forms.rst, you is being used.
I think it's the better choice, as it sounds more empowering. The reader builds, we just teach them how.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sentence sounds strange, "You will etc"...: What? No I won't! :)
Maybe:
Let's use the Maker bundle to highlight the differences between using DTOs and entities.
The example contained protected and public properties on the entity. Replaced with private.
Assumes that make:crud generates code without abbreviation.
The example entity does not use a fluent interface. This also makes the generated code easier to read.
The type is specified.
form/data_transfer_objects.rst
Outdated
|
||
Data Transfer Objects can be used by forms to separate entities from the | ||
validation logic of forms. | ||
Entities should always have a valid state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed - adds no value IMHO
form/data_transfer_objects.rst
Outdated
When the validation fails, the invalid data is still left in the entity. | ||
This can lead to invalid data being saved in the database. | ||
|
||
You will use the Maker bundle to highlight the differences between using DTOs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sentence sounds strange, "You will etc"...: What? No I won't! :)
Maybe:
Let's use the Maker bundle to highlight the differences between using DTOs and entities.
This PR was merged into the 1.0-dev branch. Discussion ---------- [CRUD] Remove abbreviation in var name $em As stated by @kunicmarco20 [here](symfony/symfony-docs#10588 (review)), no abbreviations should be used in var names. This PR fixes this in the generated Controller for `make:crud` Commits ------- 8176d83 Remove abbreviation in var name $em
public function fill(Task $task): Task | ||
{ | ||
$task->setTask($this->task); | ||
$task->setDueDate($this->dueDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$task->setDueDate($this->dueDate) | |
$task->setDueDate($this->dueDate); |
Using Data Transfer Objects | ||
--------------------------- | ||
|
||
There are some problems when using entities as directly mapped data classes for forms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not the word problems, but notice or info
Better write something like :
Alternatively, you can decouple your entities creation with DTO that are bound to form instead, see more
Etc
This PR has been closed because the master has been removed. |
This PR was merged into the 1.0-dev branch. Discussion ---------- [CRUD] Remove abbreviation in var name $em As stated by @kunicmarco20 [here](symfony/symfony-docs#10588 (review)), no abbreviations should be used in var names. This PR fixes this in the generated Controller for `make:crud` Commits ------- 8176d83 Remove abbreviation in var name $em
Add a short article about using data transfer objects in form handling.
The docs use a new make:dto command.
Merge when make:dto is merged.