Skip to content
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

Add more posts authors #478

Merged
merged 4 commits into from Jun 21, 2017
Merged

Conversation

voronkovich
Copy link
Contributor

For now we have only one admin: Jane Doe. Latest posts with more than one author look more naturally.

// in different files. This reference has been added in the UserFixtures
// file and it contains an instance of the User entity.
$post->setAuthor($this->getReference('jane-admin'));
// This ensures that the first post is written by Jane Doe
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need that the first Post belongs to Jane?

$crawler->filter('body#admin_post_index #main tbody tr'),
$this->assertGreaterThanOrEqual(
1,
$crawler->filter('body#admin_post_index #main tbody tr')->count(),
Copy link
Member

Choose a reason for hiding this comment

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

Since authors are randomly assigned, each time the fixtures are loaded this test would fail (depending on the authenticated user)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yceruto, Jane Doe has at least one post, so test should pass.

Copy link
Member

@yceruto yceruto Feb 18, 2017

Choose a reason for hiding this comment

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

Ooh! GreaterThanOrEqual you're right, this answers my first question too (Why do you need that the first Post belongs to Jane)

FROM AppBundle:Post p
JOIN p.author a
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK this shouldn't improved nothing, Doctrine hydrates the author without an extra query.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yceruto, I think you're wrong. See http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#joins

A join (be it an inner or outer join) becomes a “fetch join” as soon as fields of the joined entity appear in the SELECT part of the DQL query outside of an aggregate function.

Copy link
Member

Choose a reason for hiding this comment

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

Well, I think it's necessary for multiple users then 👍

@20uf
Copy link

20uf commented Apr 25, 2017

Why not just use https://github.com/nelmio/alice.
It would alleviate the code above and make it all more understandable.

@javiereguiluz
Copy link
Member

I wouldn't add the Alice bundle for such a simple demo application as this one. We want to showcase the main Symfony features ... but not turn this into a too large and too slow app.

@javiereguiluz
Copy link
Member

javiereguiluz commented Jun 21, 2017

It took me a long time, but this is finally merged! Thanks @voronkovich

@javiereguiluz javiereguiluz merged commit c891805 into symfony:master Jun 21, 2017
javiereguiluz added a commit that referenced this pull request Jun 21, 2017
This PR was merged into the master branch.

Discussion
----------

Add more posts authors

For now we have only one admin: Jane Doe. Latest posts with more than one author look more naturally.

Commits
-------

c891805 Update fixtures
eafb89e Updated the user fixtures
c366c05 Join posts authors when quering latests posts
72bddba Add more posts authors
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.

None yet

4 participants