Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMarc Burt
9,828 PointsDEPRECATION WARNING: Relation#all is deprecated.
Hi,
I followed this video and my code works, but I get a warning when running the test, I'm guessing since I'm using a newer version of rails.
The warning is 'DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. Post.where(published: true).load
). If you want to get an array of records from a relation, you can call #to_a (e.g. Post.where(published: true).to_a
). (called from show at d:/Ruby Work/Treebook/treebook/app/controllers/profiles_controller.rb:6)'
I thought I'd try the new method suggested, but can't get that correct.. My best guess at following the warning is:
Statuses.where(user: @user).to_a
What have I got wrong?
3 Answers
Andrew Rice
2,233 PointsWhoops... posted as a comment instead of an answer. Not used to this...
Here is the post as an answer:
I just figured this out myself and figured I wouldn't leave this question unanswered.
The correct code seems to be:
@statuses = @user.statuses.to_a
It still works as expected and the test passes, plus no deprecation warning.
Marc Burt
9,828 PointsThanks!
JoJo KoKo
4,712 Pointsinstead of using the new methodology, trying going back to hash rockets (=>) or use rvm to install different versions of ruby
Marc Burt
9,828 PointsSorry if it isn't clear in the questions JoJo,
I have my code working as it was explained in the video, I just can't understand the new methodology and was hoping someone could explain it.
Doug Tucker
7,437 PointsI tried @statuses = @user.statuses.load and that seemed to work from Scoping video in Track 8 in building a simple rails app
Marc Burt
9,828 PointsHi Doug,
Yes, this is the video I asked the question for - as mentioned in the question it also worked for me. The warning doesn't stop it working, just mentions the method is depreciated, which I think means it'll be phased out. I'm looking for an answer on the new method it suggests.
Andrew Rice
2,233 PointsAndrew Rice
2,233 PointsI just figured this out myself and figured I wouldn't leave this question unanswered.
The correct code seems to be:
@statuses = @user.statuses.to_a
It still works as expected and the test passes, plus no deprecation warning.