-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add user relationship to Post and Comment entities #434
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
use AppBundle\Entity\Comment; | ||
use AppBundle\Entity\Post; | ||
use AppBundle\Entity\User; | ||
use Doctrine\Common\DataFixtures\FixtureInterface; | ||
use Doctrine\Common\DataFixtures\AbstractFixture; | ||
use Doctrine\Common\Persistence\ObjectManager; | ||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
use Symfony\Component\DependencyInjection\ContainerAwareTrait; | ||
|
@@ -32,7 +32,7 @@ | |
* @author Ryan Weaver <[email protected]> | ||
* @author Javier Eguiluz <[email protected]> | ||
*/ | ||
class LoadFixtures implements FixtureInterface, ContainerAwareInterface | ||
class LoadFixtures extends AbstractFixture implements ContainerAwareInterface | ||
{ | ||
use ContainerAwareTrait; | ||
|
||
|
@@ -55,6 +55,7 @@ private function loadUsers(ObjectManager $manager) | |
$encodedPassword = $passwordEncoder->encodePassword($johnUser, 'kitten'); | ||
$johnUser->setPassword($encodedPassword); | ||
$manager->persist($johnUser); | ||
$this->addReference('john-user', $johnUser); | ||
|
||
$annaAdmin = new User(); | ||
$annaAdmin->setUsername('anna_admin'); | ||
|
@@ -63,6 +64,7 @@ private function loadUsers(ObjectManager $manager) | |
$encodedPassword = $passwordEncoder->encodePassword($annaAdmin, 'kitten'); | ||
$annaAdmin->setPassword($encodedPassword); | ||
$manager->persist($annaAdmin); | ||
$this->addReference('anna-admin', $annaAdmin); | ||
|
||
$manager->flush(); | ||
} | ||
|
@@ -76,13 +78,13 @@ private function loadPosts(ObjectManager $manager) | |
$post->setSummary($this->getRandomPostSummary()); | ||
$post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); | ||
$post->setContent($this->getPostContent()); | ||
$post->setAuthorEmail('[email protected]'); | ||
$post->setAuthor($this->getReference('anna-admin')); | ||
$post->setPublishedAt(new \DateTime('now - '.$i.'days')); | ||
|
||
foreach (range(1, 5) as $j) { | ||
$comment = new Comment(); | ||
|
||
$comment->setAuthorEmail('[email protected]'); | ||
$comment->setAuthor($this->getReference('john-user')); | ||
$comment->setPublishedAt(new \DateTime('now + '.($i + $j).'seconds')); | ||
$comment->setContent($this->getRandomCommentContent()); | ||
$comment->setPost($post); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we need an extra check here since the user variable might be
null
:Uh oh!
There was an error while loading. Please reload this page.
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.
For extra readability? when the user is
null
anyway it already returnsfalse
.Edit: it was necessary before since we check
$user->getEmail()
;)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.
@yceruto, both variables
$user
and$this->author
can be null at the same time.Uh oh!
There was an error while loading. Please reload this page.
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.
@voronkovich It shouldn't happen I think, as each
Post
is initialized with its author and is required also. I'm missing something?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.
@yceruto, you're right! So, we don't need to check the user variable for null value here.
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.
As Oleg said, both variables $user and $this->author can be null at the same time - I just want to prevent weird bugs in the future. I think it's unsafe just rely on
nullable
option which could be changed.Uh oh!
There was an error while loading. Please reload this page.
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.
@bocharsky-bw Sorry for the delay, I understand your preoccupation, but apparently that case is not possible. If a post exists this have an author and this field is not nullable in the database either. Thanks for the discussion guys, but I don't think it's worth it :)
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.
All of you have given good reasons ... so let's keep this as it is to move on ... and we'll add the extra check if needed in the future. Thanks!