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 user relationship to Post and Comment entities #434

Merged
merged 1 commit into from
Jan 19, 2017
Merged

Add user relationship to Post and Comment entities #434

merged 1 commit into from
Jan 19, 2017

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Jan 14, 2017

Actually, we are related Post/User and Comment/User indirectly throught authorEmail field which IMHO makes things more complicated to understand for the beginner, because really we need this relationship.

Related discussion in #429.

@voronkovich
Copy link
Contributor

@yceruto, I think we don't need the relation between User and Comment. It's better to allow anonymous users create comments.

@yceruto
Copy link
Member Author

yceruto commented Jan 14, 2017

@voronkovich before this PR to comment on Post is required to be logged, just I keep the current behavior for now :)

@voronkovich
Copy link
Contributor

@yceruto, ok, let's keep it as is for now.

{
$this->publishedAt = $publishedAt;
return $user === $this->author;
Copy link
Contributor

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:

if (null === $user) {
    return false;
}

Copy link
Member Author

@yceruto yceruto Jan 15, 2017

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 returns false.

Edit: it was necessary before since we check $user->getEmail() ;)

Copy link
Contributor

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.

Copy link
Member Author

@yceruto yceruto Jan 15, 2017

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

@yceruto yceruto Jan 17, 2017

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 :)

Copy link
Member

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!

@yceruto
Copy link
Member Author

yceruto commented Jan 17, 2017

Rebase with master and added more tests.

@javiereguiluz
Copy link
Member

javiereguiluz commented Jan 19, 2017

This was a much needed improvement. @yceruto thanks for contributing this feature.

@javiereguiluz javiereguiluz merged commit 52d2fa3 into symfony:master Jan 19, 2017
javiereguiluz added a commit that referenced this pull request Jan 19, 2017
…uto)

This PR was merged into the master branch.

Discussion
----------

Add user relationship to Post and Comment entities

Actually, we are related Post/User and Comment/User indirectly throught `authorEmail` field which IMHO makes things more complicated to understand for the beginner, because really we need this relationship.

Related discussion in #429.

Commits
-------

52d2fa3 Add user relationship to Post and Comment entities
@yceruto yceruto deleted the user-relationship branch January 19, 2017 13:22
javiereguiluz added a commit that referenced this pull request Jan 20, 2017
This PR was merged into the master branch.

Discussion
----------

Added more tests for the backend

This complements the new tests added in #434.

Commits
-------

4cfce12 Added more tests for the backend
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