1000 search results

Creating Embedded Objects

…>persist() on that new CheeseListing, which is why Doctrine isn't sure what to do when trying to save the User. If this were a traditional Symfony app where I'm personally writing the code to create and save these objects, I'd probably just…

7:06
Embedded Write

… But the error is fascinating! A new entity was found through the relationship CheeseListing.owner that was not configured to cascade persist operations for entity User. If you've been around Doctrine for awhile, you might recognize this strange error. Ignoring API Platform for a…

8:22
Relating Resources

…that up... just to make sure it doesn't contain anything extra. Looks good - altering the table and setting up the foreign key. Execute that: php bin/console doctrine:migrations:migrate Oh no! It exploded! Cannot add or update a child row, a foreign key…

7:38
PropertyFilter: Sparse Fieldsets

…From a high-level, a filter is basically a way for you to modify the Doctrine query that's made when fetching a collection. There's one more filter I want to talk about... and it's a bit special: instead of returning less results…

5:34
User API Resource

…auto-increment id, one option is to use a UUID. We're not going to use them in this tutorial, but using a UUID as your identifier is something that's supported by Doctrine and API Platform. UUIDs work with any database, but they are…

7:20
Validation

…earlier, if you're using Symfony 4.3, you might already see a validation error instead of a database error because of a new feature where validation rules are automatically added by reading the Doctrine database rules. But, whether you're seeing a 500 error…

6:29
Filtering & Searching

…at the top of your class, add use BooleanFilter. But... careful... most filters support Doctrine ORM and Doctrine with MongoDB. Make sure to choose the class for the ORM. Ok, now move over and refresh again. We're back to life! Click "Try it out…

6:02
A bit of Security Cleanup

…with our User class so we get auto-completion. Back down in our method, we can say $this->getUser()->getArticles()->isEmpty(), which is a method on Doctrine's Collection object. So, if we don't have ROLE_ADMIN_ARTICLE and we are not the author…

7:02
Clear that Location Name Data

…location is star, specificLocationName is Rigel and id is 28. Let's go verify this in the database: find your terminal and run: php bin/console doctrine:query:sql 'SELECT * FROM article WHERE id = 28' Yep! All the data looks like we expected! But…

5:09
Agree to Terms Checkbox Field

…bit of glue code in your controller that does whatever you need. Later, we'll discuss a third option: creating a custom model class for your form. Before we move on, try to reload the fixtures: php bin/console doctrine:fixtures:load It... explodes! Duh…

5:35
Setup: For Dependent Select Fields

…location will be optional. Now run: php bin/console make:migration and open the Migrations/ directory to check out that new file. No surprises here, so let's go back and run it: php bin/console doctrine:migrations:migrate Perfect! Next, open the ArticleFormType so…

6:41
Tweak your Form based on the Underlying Data

…with some default data. The form system would update that Article object, but Doctrine would still be smart enough to insert a new row when we save. Anyways, that's why I'm checking not only that the Article is an object, but that it…

8:35
Autocomplete Endpoint & Serialization Group

…that URL, open a new tab paste and.... boo! A circular reference has been detected. This is a common problem with the serializer and Doctrine objects. Check it out: open the User class. By default, the serializer will serialize every property... or more accurately, every…

5:26
Agree to Terms Database Field

…directory, open that file and... yep! It adds the one field. Run it with: php bin/console doctrine:migrations:migrate Oh no! Things are not happy. We have existing users in the database! When we suddenly create a new field that is NOT NULL, MySQL…

6:03
The Edit Form

…Go to /article/1/edit. Dang - I don't have an article with id Let's go find a real id. In your terminal, run: php bin/console doctrine:query:sql 'SELECT * FROM article' Perfect! Let's us id 26. Hello, completely pre-filled form…

7:18
HTML5 & "Sanity" Validation

…can be kind of annoying & surprising. However, when you bind your form to an entity class, the form field guessing system uses the nullable Doctrine option to choose the correct required option value for you. In fact, if we look at the textarea field... yep…

6:19
EntityType: Drop-downs from the Database

…Anyways, we'll see in a minute how we can control what's displayed here. So... great first step! It looks like the form guessing system correctly sees the Doctrine relation to the User entity and configured the EntityType for us. Go team! But now…

7:33
Impersonation (switch_user)

…is also used by a few other features to load the user, like remember_me and switch_user. If you're using the Doctrine user provider like we are, then this property key determines which field will be used for all of this: If you…

6:30
Author ManyToOne Relation to User

…use $this->getRandomReference('main_users') to get a random User object from that group: At the top of the class, I can remove this old static property. Try it! Move over and run: php bin/console doctrine:fixtures:load It works! But... only by chance…

7:07
API Token Authenticator

…in a minute. But first, move over to your terminal: we need to find a valid API key! Run: php bin/console doctrine:query:sql 'SELECT * FROM api_token' Copy one of these long strings, move back to Postman and paste! To see what this…

7:01