Skip to content

Doctrine update for Flex #8729

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

Merged
merged 8 commits into from
Nov 27, 2017
Merged

Doctrine update for Flex #8729

merged 8 commits into from
Nov 27, 2017

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Nov 21, 2017

Hi guys!

This is an update to 4.0. But... I basically rewrote the main doctrine.rst page and also doctrine/associations.rst. All the rest is just a simple directory structure update. I made many changes, but I DID code through all of them, so we don't need to review the code for "will this actually work?" type of stuff :).

  • verify that the section where we talk about "line 12 does this" is still accurate to the lines

doctrine.rst Outdated
*/
private $id;

/**
* @ORM\Column(type="string", length=100)
* @ORM\Column(type="string", length=100, nullable=false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is nullable=false by default for @ORM\Column annotation.

doctrine.rst Outdated
Be careful not to use reserved SQL keywords as your table or column names
(e.g. ``GROUP`` or ``USER``). See Doctrine's `Reserved SQL keywords documentation`_
for details on how to escape these. Or, configure the table name with
``@ORM\Table(name="groups")`` or the column name with the ``name="group_name"``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about to show directly how to escape keywords here? @ORM\Table(name="`group`") or the column name with the name="`group`"


.. tip::
// ...
class ProductRepository extends ServiceEntityRepository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are extending from ServiceEntityRepository shouldn't assume that this class is intended to be a service and autowired? if yes, we might need the __constructor to set the entityClass?

doctrine.rst Outdated
ORDER BY p.price ASC
';
$stmt = $conn->prepare($sql);
$stmt->execute(array('price' => 10));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ ] ?

* @ORM\ManyToOne(targetEntity="Category", inversedBy="products")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
* @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="products")
* @ORM\JoinColumn(nullable=true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it isnullable=true by default for @ORM\JoinColumn annotation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea... but I do want it to be nullable (it just makes the example easier, no error in case you already have Products in the database) but I also want to show this option so that people are thinking about it.

@weaverryan weaverryan changed the title [WIP] Doctrine update for Flex Doctrine update for Flex Nov 24, 2017
@weaverryan weaverryan added this to the 4.0 milestone Nov 24, 2017
@weaverryan
Copy link
Member Author

This is ready for review!

Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!! I loved every change :)

@@ -301,24 +335,24 @@ What's important is the fact that you have easy access to the product's related
category, but the category data isn't actually retrieved until you ask for
the category (i.e. it's "lazily loaded").

You can also query in the other direction::
Because we mapped the optiona ``OneToMany`` side, you can also query in the other
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional?

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great changes and simplifications. Thanks!

doctrine.rst Outdated
We recommend against MySQL's ``utf8`` character set, since it does not
support 4-byte unicode characters, and strings containing them will be
truncated. This is fixed by the `newer utf8mb4 character set`_.
There are more optiosn in ``config/packages/doctrine.yaml`` that you can configure,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optiosn -> options

doctrine.rst Outdated
),
));
There are many other Doctrine commands. To see a full list, run
``php bin/console list doctrine``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The . after a command is always troublesome because some people will add it when executing it. We could change the order in this phrase to avoid the dot:

Run ``php bin/console list doctrine`` to see the full list.

}

.. code-block:: yaml

# src/Resources/config/doctrine/Product.orm.yml
# config/doctrine/Product.orm.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this new path works as expected? I'd love to because it's much better!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it can be configurable too:

doctrine:
    orm:
        # ...
        mappings:
            App:
                is_bundle: false
                type: yml
                dir: '%kernel.project_dir%/config/doctrine' # <--- custom path
                prefix: 'App\Entity'
                alias: App

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, you must add the config that @yceruto showed for this to work.

doctrine.rst Outdated
.. note::
Doctrine supports a wide variety of different field types, each with their own options.
To see a full list of types and options, see `Doctrine's Mapping Types documentation`_.
If you want to use ``xml`` instead of annotations, you'll need to configure this in your
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this phrase -> "If you want to use xml instead of annotations, you'll need to configure this in your config/packages/doctrine.yaml file." the part about "... you'll need to configure this ..." to me means that you are going to show me now what should I configure. Not sure if I explained my self, but something like this could be more clear:

If you want to use XML instead of annotations, add ``type: xml`` to the entity mappings in
your ``config/packages/doctrine.yaml`` file.

doctrine.rst Outdated

If you're following along with this example, you'll need to create a
route that points to this action to see it work.
Congratulations! You just created your first row the ``product`` table. To prove it,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your first row the -> your first row IN the

doctrine.rst Outdated
WHERE p.price > :price
ORDER BY p.price ASC'
)->setParameter('price', 19.99);
When you fetch your repository (i.e. ``->getRepository(Product::class)``, it is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parenthesis of (i.e. .. is lacking a closing parenthesis.

charset: UTF8
server_version: 5.6
# customize this line!
DATABASE_URL="mysql://db_user:[email protected]:3306/db_name?charset=utf8mb4&serverVersion=5.7"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should charset=utf8mb4&serverVersion=5.7 be removed in this DATABASE_URL env var?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@weaverryan weaverryan merged commit 39c4a83 into symfony:4.0 Nov 27, 2017
weaverryan added a commit that referenced this pull request Nov 27, 2017
This PR was squashed before being merged into the 4.0 branch (closes #8729).

Discussion
----------

Doctrine update for Flex

Hi guys!

This is an update to 4.0. But... I basically rewrote the main `doctrine.rst` page and also `doctrine/associations.rst`. All the rest is just a simple directory structure update. I made many changes, but I DID code through all of them, so we don't need to review the code for "will this actually work?" type of stuff :).

* [ ] verify that the section where we talk about "line 12 does this" is still accurate to the lines

Commits
-------

39c4a83 fixes thanks to the team!
04603c7 Fixing build problems
59c6b0d tweaks thanks to @yceruto
2b0236f updating the rest of the Doctrine docs
68ac454 WIP - updating associations article
7e77d9c moving section down
6259931 Finishing major overhaul of the main Doctrine chapter
4938678 WIP - starting to upgrade Doctrine doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants