-
Notifications
You must be signed in to change notification settings - Fork 0
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
Milestone 2: models associations #2
Conversation
- Add all the required models methods.
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.
Hi @ITurres,
Good job so far!
There are some issues that you still need to work on to go to the next project but you are almost there!
Highlights
- Good PR title β
- Descriptive PR description β
- Implement the features β
- Nice UI design β
- Professional
README
template β - Correct
GitHub
workflow β - Meaningful Github commits β
- Correct
.github/workflows
for linters β - Followed best-practices β
- Well structured project β
Required Changes β»οΈ
Check the comments under the review.
Optional suggestions
Every comment with the [OPTIONAL] prefix is not crucial enough to stop the approval of this PR. However, I strongly recommend you to take them into account as they can make your code better.
Cheers and Happy coding!πππ
Feel free to leave any questions or comments in the PR thread if something is not 100% clear.
Please, remember to tag me in your question so I can receive the notification.
Please, do not open a new Pull Request for re-reviews. You should use the same Pull Request submitted for the first review, either valid or invalid unless it is requested otherwise.
As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.
app/models/post.rb
Outdated
@@ -0,0 +1,13 @@ | |||
class Post < ApplicationRecord | |||
belongs_to :author, class_name: 'User', foreign_key: :author_id_id |
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.
-
Great job so far! π You're on the right track with setting up the associations in your models. However, there are a couple of improvements and corrections needed. Let's dive into the review:
- In Rails, when you define associations like
has_many
orbelongs_to
, Rails automatically assumes the foreign key based on naming conventions unless you explicitly specify it. So, you don't need to add_id
in the foreign key names when using the typical Rails naming conventions.
- In Rails, when you define associations like
Instead of ππ
belongs_to :author, class_name: 'User', foreign_key: :author_id_id
Do this ππ
belongs_to :author, class_name: 'User', foreign_key: :author_id
Happy coding!
|
||
def update_posts_counter | ||
author.increment!(:posts_counter) | ||
end |
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.
- Great work on defining the methods for your post model! π To enhance the maintainability and organization of your code, I recommend considering the use of Rails Active Callbacks, specifically
after_save
, to automatically trigger theupdate_posts_counter
method each time a new post is saved to the database. This approach will help you keep your code clean and ensure that the counter is always up to date without manual intervention.
Below is an example of making use of after_save
:
after_save :update_posts_counter
def update_posts_counter
author.increment!(:posts_counter)
end
Keep up the good work! ππ
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.
Hi @Strangeal! Oh, nice π―, thank you for the suggestion! I will totally implement it now. π₯
def update_comments_counter | ||
post.increment!(:comments_counter) | ||
end |
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.
Hint : Just like I mentioned in my second comment, after_save :update_comments_counter
def update_likes_counter | ||
post.increment!(:likes_counter) | ||
end |
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.
Hint : Just like I mentioned in my second comment, after_save : update_likes_counter
π΄Note: |
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.
Hi @ITurres π
Your project is complete! There is nothing else to say other than... it's time to merge it
Congratulations! π
Highlights
- Good project organization βοΈ
- Nice use of Rails features βοΈ
- Kudus on meeting the requirements as pointed the last time out by the last reviewer π
Optional suggestions
Every comment with the [OPTIONAL] prefix won't stop the approval of this PR. However, I strongly recommend you take them into account as they can make your code better. Some of them were simply missed by the previous reviewer and addressing them will really improve your application.
Feel free to leave any questions or comments in the PR thread if something is not 100% clear.
Please, remember to tag me in your question so I can receive the notification.
As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.
Hey @Shedrack-Sunday! Cheers for approving the PR π₯, @Strangeal comments were very helpful. Wish you both a great week! and happy coding π¨πΌβπ». |
π©I have made the following changes to complete Milestone 2
Here is a summary of what has been done
Type of
files
changed/addedIn this new Branch, I have βADDEDβ the succeeding *π folders and/or **π files to complete this milestone requirements
*π root/
*π app/
**π user.rb β
**π post.rb β
**π comment.rb β
**π like.rb β
I have βοΈMODIFIEDβοΈ the succeeding *π folders and/or π** files
*π root/
**π README.md β
*π db/
**π schema.rb β
*π migrate/
**π 20231128225500_create_posts.rb β
_id
on:author
reference atCreatePosts
migration for consistency.**π 20231128225646_create_comments.rb β
t.references :post, null: false, foreign_key: true
before:user
but lately I have set it as it was (after ':user' - see commit history). Keeping their positions consistency as elsewhere.Thank you for taking the time to review this PR β
If you need additional information or have any questions, please don't hesitate to contact me on Slack as Arturo (Arthur) Emanuel Guerra Iturres. I'll be happy to help you out. π―