Git Product home page Git Product logo

model-class-methods-lab's Introduction

Optimal Queries using Active Record

Learning Goals

  • Use ActiveRecord's AREL library to build optimized queries

Introduction

In programming, a good maxim is this:

Use the best tool for the job

For example, you don't want to use JavaScript to build a computer for flying to the Moon. JavaScript doesn't have very good decimal precision and, at distances as far as the Moon, getting a number off in the hundred-thousandths place after the decimal is the difference between landing on that celestial orb or taking a long trip through nothing, forever.

Databases are AMAZING at linking and summarizing data. Ruby is a nice general-purpose programming language. So when we need to get data from a database, we want to ask the DATABASE to do as much of that work as possible. That's what it's good at. That's what it likes to do. It has sacrificed some capabilities in order to do other capabilities extremely well.

If you use this code:

doctors = Doctor.all
first_six_drs = doctors[0..5]

You will get six doctors by using RUBY to "section off" six doctors using Ruby's range method ([]). But under the covers we asked the database for all the doctors and then took six of them. Wouldn't it make more sense to ask the database to get us only six Doctors in the first place? That's what the following code does:

Doctor.limit(6).to_a

ActiveRecord has a number of "finder" methods like limit built right in. These methods let us query the database, via ActiveRecord, in an object-oriented-looking way that uses as much of the database's power as possible.

Use ActiveRecord's Finder Methods To Build Optimized Queries

In this lab, we've provided the solution (commented out) to the tests. You should step through the tests and "fix" each method to make the test pass.

As you uncomment, be sure to evaluate the implementation we've provided you. Methods like order, where, includes are all ActiveRecord finder methods. You should look up these methods in the ActiveRecord Query Interface documentation, and see how they're working to filter the data retrieved from the database before the result "gets to Ruby-land."

Conclusion

While it's not necessary to memorize all the chainable methods ActiveRecord provides, it's best to know some of the common methods you saw in this lab. If you are working in a Rails environment, finder methods can make your queries more efficient, which can literally speed up your applications 1000x!

model-class-methods-lab's People

Contributors

ahimmelstoss avatar annjohn avatar arelenglish avatar aspenjames avatar aviflombaum avatar danielseehausen avatar dependabot[bot] avatar drakeltheryuujin avatar fislabstest avatar fs-lms-test-bot avatar ihollander avatar irmiller22 avatar kthffmn avatar lizbur10 avatar loganhasson avatar maxwellbenton avatar pletcher avatar roseweixel avatar sarogers avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

model-class-methods-lab's Issues

Known Issues

Problems:

  • Readme needs rewrite/Removal of bad resource content:

"This is the most frustrating lab in this curriculum yet. Not because it is hard. But because there is no teaching or guidance."

"After reading this article, I feel like the AREL resource should be replaced with this.http://guides.rubyonrails.org/active_record_querying.html"

"I was very confused/lost on how one should reference other models

"..require writing more than one method in more than one model."

It would have been helpful to have some examples, as I did not fully understand what was meant by that statement, and I ended up somehow doing the lab without really crossreferencing any methods between models"

"This lab should not that you have to use the rails command "rails console" instead of rake console.

Also the file structure does not match what the prior read me has indicated.

ALSO AREL who knows what that is yet???"

  • Issues reports on lab opening/completion errors:

"Clicking Open button on page:
https://learn.co/tracks/full-stack-web-dev-with-react/rails/refactoring-with-helpers-and-model-methods/model-class-methods-lab#

Results in the following Learn-IDE error:
learn open model-class-methods-lab-v-000
Looking for lesson...
Hmm...Cannot find lesson with repo: model-class-methods-lab-v-000. Please check your input and try a
gain.
[19:44:22] labs
// ♥"

"Have re-forked and resubmitted this lab multiple times, all to no avail. Lesson page shows as completed, even having the "Next Lesson" and Solution buttons pop up. However, it doesn't show up as completed on my profile progress counter nor the curriculum tab."

"This lab does not pull the repo properly in either IDE Download or Browser.
had to use refresh_ssh, then whenever I close IDE, and open again, it does not connect again."

"Multiple attempts made and refreshed the page twice. I was able to manually fork and clone it."

  • Lack of information/guidance
  • Test problems, rspec doesn't drop database when run:

"My pairing partner (and most students) use the .find method in order to find the first_five instances in the database. However, .first returns an array and pluck expects an active_record_relation which causes the test to fail even though the information looks identical. I believe it is a good idea to change the spec file so we can use the .find function."

"In the ::non_sailors test it expects three captains for a result. According to the data given in seeds there are six captains that don't have sailboats.
h_28.classifications << [ketch, sailboat] nacra_17.classifications << [catamaran, sloop, sailboat] regulator.classifications << [motorboat, center] zodiac.classifications << [rib, motorboat, center] boston_whaler.classifications << [motorboat] forty_niner.classifications << [sailboat, sloop] cape_dory.classifications << [motorboat, trawler] laser.classifications << [sailboat, cat_rig] triton.classifications << [motorboat, bass] sun_tracker.classifications << [motorboat, pontoon, catamaran] harpoon.classifications << [sailboat, sloop] sunfish.classifications << [sailboat, cat_rig]

I fixed it here by having it expect the correct amount of captains:
describe "::non_sailors" do it "returns people who are not captains of sailboats" do captains = ["Captain Cook", "Captain Kidd", "William Kyd", "Arel English", "Henry Hudson", "Samuel Axe"] expect(Captain.non_sailors.pluck(:name)).to eq(captains) end"

"I don't see how this test can pass. I've manually checked the data, and there appear to be 6 captains of Motorboats and Sailboats, not 2. Unless the wording needs to be changed to indicate that you want those captains who have captained a Motorboat AND a Sailboat."

  def self.first_five
    self.first(5)
  end

this returns an Array instance correctly containing the first 5 boats but the rspec test case expects the boats returned in an Boat::ActiveRecord_Relation so that it can respond to #pluck.

Changing my implementation to the following passes the test:

  def self.first_five
    self.all.limit(5)
  end

Instructions do not provide any guidance regarding implementation of this method and so it makes sense to choose my original implementation using the simpler Boat.first(n).

I believe that either more direction should be provided in the instructions or the test case should not assume return of an ActiveRecord_Relation.

Failures:

Captain::talented_seamen returns captains of motorboats and sailboats
expected: ["Captain Cook", "Samuel Axe"]
got: ["Captain Cook", "Captain Kidd", "William Kyd", "Arel English", "Henry Hudson", "Samuel Axe"]"

Errors:
can not open rails console due to subject error: /usr/local/rvm/gems/ruby-2.3.1/gems/railties-4.2.0/lib/rails/commands/console.rb:29:in `bloc k in parse_arguments': invalid option: -b (OptionParser::InvalidOption)

Lab doesn't check off as completed in the curriculum module.

Have re-forked and resubmitted this lab multiple times, all to no avail. Lesson page shows as completed, even having the "Next Lesson" and Solution buttons pop up. However, it doesn't show up as completed on my profile progress counter nor the curriculum tab.

Bundle fails on install

Bundle fails on install

Expected Behavior

bundle or bundle install installs dependencies

Observed Behavior

bundle or bundle install fails with incompatible version

// ♥ bundle
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "bundler":
  In Gemfile:
    rails (= 4.2) was resolved to 4.2.0, which depends on
      bundler (>= 1.3.0, < 2.0)

  Current Bundler version:
    bundler (2.0.1)
This Gemfile requires a different version of Bundler.
Perhaps you need to update Bundler by running `gem install bundler`?

Could not find gem 'bundler (>= 1.3.0, < 2.0)', which is required by gem 'rails (= 4.2)', in
any of the sources.

Cause

Breaking changes in Bundler v2.0

One of the features of Bundler v2.0 is version is "version autoswitching", which you can read about here. This feature requires a Gemfile.lock to be committed into VC, and the Gemfile.lock is currently .gitignored.

Remedy

Check in Gemfile.lock to git. Output below shown on commit c853032, which was immediately prior to Gemfile.lock being removed from git:

[16:05:51] ((HEAD detached at c853032)) model-class-methods-lab-v-000
// ♥ bundle
Fetching gem metadata from https://rubygems.org/..........
======
snip
======
Bundle complete! 12 Gemfile dependencies, 62 gems now installed.

#Staff

Captain Non Sailors Test Wrong

In the ::non_sailors test it expects three captains for a result. According to the data given in seeds there are six captains that don't have sailboats.
h_28.classifications << [ketch, sailboat] nacra_17.classifications << [catamaran, sloop, sailboat] regulator.classifications << [motorboat, center] zodiac.classifications << [rib, motorboat, center] boston_whaler.classifications << [motorboat] forty_niner.classifications << [sailboat, sloop] cape_dory.classifications << [motorboat, trawler] laser.classifications << [sailboat, cat_rig] triton.classifications << [motorboat, bass] sun_tracker.classifications << [motorboat, pontoon, catamaran] harpoon.classifications << [sailboat, sloop] sunfish.classifications << [sailboat, cat_rig]

I fixed it here by having it expect the correct amount of captains:
describe "::non_sailors" do it "returns people who are not captains of sailboats" do captains = ["Captain Cook", "Captain Kidd", "William Kyd", "Arel English", "Henry Hudson", "Samuel Axe"] expect(Captain.non_sailors.pluck(:name)).to eq(captains) end

Cannot migrate

Thanks for raising this issue! Future learners thank you for your diligence. In
order to help the curriculum team address the problem, please use this template
to submit your feedback. We'll work on addressing the issue as soon as we can.

Please fill out as much of the information below as you can (it's ok if you
don't fill out every section). The more context we have, the easier it will be
to fix your issue!

Note: you should only raise issues related to the contents of this lesson.
If you have questions about your code or need help troubleshooting, reach out to
an instructor/your peers.


Link to Canvas

course link

Describe the bug

According to the error. The repo is missing a manifest file in the assets directory.
Sprockets::Railtie::ManifestNeededError: Expected to find a manifest file in app/assets/config/manifest.js

What is the expected behavior?

I would expect to be able to begin work on the lab.

Screenshots

image

What OS are you using?

  • [ x ] OS X
  • WSL
  • Linux

Any additional context?

Add any other context about the problem here.

Pending migration and test suite errors

Have had a number of issues with this lab. Originally had a problem where I didn't have ruby 2.2.0 installed. This lab sets the ruby version as 2.2.0 in the Gemfile and .ruby-version files. Installing ruby 2.2.0 didn't end up solving the issue.

I asked Learn support for help and they told me 2.2.3(the version I've been using all this time) should work fine for this lab.

After deleting the ruby version in the Gemfile and .ruby-version to mimic past Rails labs, things appeared to work. See my commit here: alexbarron/model-class-methods-lab-v-000@f6339f1

I ran 'rake db:migrate RAILS_ENV=test' and this ran fine. I ran the test suite and that ran fine.

However, running the test suite a second time results in the following error:

♥ learn
/Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/activerecord-4.2.0/lib/active_record/migration.rb:393:in `check_pending!':  (ActiveRecord::PendingMigrationError)

Migrations are pending. To resolve this issue, run:

    bin/rake db:migrate RAILS_ENV=test

    from /Users/alexbarron/Development/code/model-class-methods-lab-v-000/spec/spec_helper.rb:13:in `<top (required)>'
    from /Users/alexbarron/Development/code/model-class-methods-lab-v-000/spec/models/boat_spec.rb:1:in `require'
    from /Users/alexbarron/Development/code/model-class-methods-lab-v-000/spec/models/boat_spec.rb:1:in `<top (required)>'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.2.1/lib/rspec/core/configuration.rb:1226:in `load'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.2.1/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.2.1/lib/rspec/core/configuration.rb:1224:in `each'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.2.1/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.2.1/lib/rspec/core/runner.rb:97:in `setup'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.2.1/lib/rspec/core/runner.rb:85:in `run'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.2.1/lib/rspec/core/runner.rb:70:in `run'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.2.1/lib/rspec/core/runner.rb:38:in `invoke'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.2.1/exe/rspec:4:in `<top (required)>'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/bin/rspec:23:in `load'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/bin/rspec:23:in `<main>'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
    from /Users/alexbarron/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'

Running rake:db migrate RAILS_ENV=test again results in this error(below is shortened version):

♥ rake db:migrate RAILS_ENV=test
== 20140313192355 CreateBoats: migrating ======================================
-- create_table(:boats)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "boats" already exists: CREATE TABLE "boats" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "length" integer, "captain_id" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /Users/alexbarron/.rvm/gems/ruby-2.2.3/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize'

Running rake db:reset RAILS_ENV=test allows me to migrate the test DB again, run the tests one more time, but then returns the same error as before.

Ian from Learn.co chat support was able to reproduce this error and he recommended I raise this as an issue.

Captain::talented_seamen test not passing

I don't see how this test can pass. I've manually checked the data, and there appear to be 6 captains of Motorboats and Sailboats, not 2. Unless the wording needs to be changed to indicate that you want those captains who have captained a Motorboat AND a Sailboat.

Failures:

  1. Captain::talented_seamen returns captains of motorboats and sailboats
    expected: ["Captain Cook", "Samuel Axe"]
    got: ["Captain Cook", "Captain Kidd", "William Kyd", "Arel English", "Henry Hudson", "Samuel Axe"]

Implementation of Boat.first_five using ActiveRecord.find fails rspec

I implemented Boat.first_five as follows:

  def self.first_five
    self.first(5)
  end

this returns an Array instance correctly containing the first 5 boats but the rspec test case expects the boats returned in an Boat::ActiveRecord_Relation so that it can respond to #pluck.

Changing my implementation to the following passes the test:

  def self.first_five
    self.all.limit(5)
  end

What is confusing to me is that the instructions do not provide any guidance regarding implementation of this method and so it makes sense to choose my original implementation using the simpler Boat.first(n).

I believe that either more direction should be provided in the instructions or the test case should not assume return of an ActiveRecord_Relation.

My Learn IDE can't find this lesson.

When I click "Open IDE", my IDE cannot find this lesson. I haven't had this issue with any other lessons so there must be something going on here.

The tests are not able to pass at all.

I've been on this lab for a little while trying to figure out whyI'm not able to get those tests passing even when using the exact same code in the solution branch. My errors are coming from the Boat Model of this lab. Even attempting to solve the lab with the find_by() method is not useful because rspec uses the pluck method to pull the information.

Im not sure why I have duplicate boats when I migrate only once and the tests are only creating the objects once.

Boat
::first_five
returns the first five Boats
::dinghy
returns boats shorter than 20 feet
::ship
returns boats 20 feet or longer
::last_three_alphabetically
returns last three boats in alphabetical order (FAILED - 1)
::without_a_captain
returns boats without a captain (FAILED - 2)
::sailboats
returns all boats that are sailboats (FAILED - 3)
::with_three_classifications
returns boats with three classifications (FAILED - 4)

Captain
::catamaran_operators
returns all captains of catamarans (FAILED - 5)
::sailors
returns captains with sailboats (FAILED - 6)
::talented_seamen
returns captains of motorboats and sailboats (FAILED - 7)
::non_sailors
returns people who are not captains of sailboats (FAILED - 8)

Classification
::my_all
returns all classifications (FAILED - 9)
#longest
returns the classifications for the longest boat (FAILED - 10)

Failures:

  1. Boat::last_three_alphabetically returns last three boats in alphabetical order
    Failure/Error: expect(Boat.last_three_alphabetically.pluck(:name)).to eq(boats)
   expected: ["Zodiac CZ7", "Triton 21 TRX", "Sunfish"]
        got: ["Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7"]

   (compared using ==)
 # ./spec/models/boat_spec.rb:28:in `block (3 levels) in <top (required)>'
  1. Boat::without_a_captain returns boats without a captain
    Failure/Error: expect(Boat.without_a_captain.pluck(:name)).to eq(boats)
   expected: ["Harpoon 4.7", "Sunfish"]
        got: ["Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish", "Harpoon 4.7", "Sunfish"]

   (compared using ==)
 # ./spec/models/boat_spec.rb:35:in `block (3 levels) in <top (required)>'
  1. Boat::sailboats returns all boats that are sailboats
    Failure/Error: expect(Boat.sailboats.pluck(:name)).to eq(boats)
   expected: ["H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish"]
        got: ["H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish", "H 28", "Nacra 17", "49er", "Laser", "Harpoon 4.7", "Sunfish"]

   (compared using ==)
 # ./spec/models/boat_spec.rb:42:in `block (3 levels) in <top (required)>'
  1. Boat::with_three_classifications returns boats with three classifications
    Failure/Error: expect(Boat.with_three_classifications.pluck(:name).sort).to eq(boats)
   expected: ["Nacra 17", "Sun Tracker Regency 254 XP3", "Zodiac CZ7"]
        got: ["Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Nacra 17", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Sun Tracker Regency 254 XP3", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7", "Zodiac CZ7"]

   (compared using ==)
 # ./spec/models/boat_spec.rb:49:in `block (3 levels) in <top (required)>'

No Need for Arel

Maybe I misunderstood the intention of this lab, but adding the Arel references is confusing. I appreciate knowing that Arel is the underpinning of ActiveRecord, but suggesting to build these queries with Arel seems to be unnecessary. The solution doesn't use any Arel, so there is no way to check on solutions.

Also, the solution provided uses some nice tricks, and I've seen some solutions like this before. For instance using the "id" field with where and the "&" operator. I'm sure not if there are best practices instead of trying to built one single query.

Perhaps clarifying the inclusion of the Arel information and providing a few suggestions on query construction would be helpful in this lab.

Self-Paced Lesson "Optimal Queries using Active Record" link redirects/out of date

Canvas Link

https://learning.flatironschool.com/courses/1881/assignments/125549?module_item_id=259444

Concern

Hi FI team,

Two "AREL documentation" links redirect to the RoR Guide at https://guides.rubyonrails.org/active_record_querying.html.

This is somewhat confusing as the lesson refers to the AREL documentation specifically and suggests the user to reference that directly.

TY for your help!

Additional Context

This might be due to AREL being moved from an independent Ruby gem to now be wrapped within the Active Record gem itself.

As of ~May 2020, the Rails Core team "consider Arel private API of the framework and we don’t recommend developers to use."

Link to discussion for reference:
https://discuss.rubyonrails.org/t/what-has-happened-to-arel/74383/6

Suggested Changes

No response

Rspec not cleaning up the database

The spec_helper code to clean the database is not working:

config.after do
(ActiveRecord::Base.subclasses - [ActiveRecord::SchemaMigration]).each(&:delete_all)
end

I am manually deleting the database and migrating each time as a workaround but can somebody look into this?

more information would be helpful

I was very confused/lost on how one should reference other models

"..require writing more than one method in more than one model."

It would have been helpful to have some examples, as I did not fully understand what was meant by that statement, and I ended up somehow doing the lab without really crossreferencing any methods between models

Issues with .spec file

Hello,

For the first test (and potentially subsequent tests), the spec file is using the pluck method in order to compare with the results we code.

My pairing partner (and most students) use the .find method in order to find the first_five instances in the database. However, .first returns an array and pluck expects an active_record_relation which causes the test to fail even though the information looks identical. I believe it is a good idea to change the spec file so we can use the .find function.

KNOWN ISSUES

#39 addresses dozens of the already raised issues.

We are in the process of updating the materials in this section and will be rewriting this lesson to address the current issues.

This lab does not open properly.

This lab does not pull the repo properly in either IDE Download or Browser.
had to use refresh_ssh, then whenever I close IDE, and open again, it does not connect again.

No Repo

This lab has no repository.

This is Not Good

This is the most frustrating lab in this curriculum yet. Not because it is hard. But because there is no teaching or guidance.

spec_helper configuration breaks rspec

When I ran rspec, then tried to run it again, I got an error saying migrations were pending. But they weren't, so running them again resulted in aborted migrations. So I was resetting the database after every run. I just lost a day thinking it was something to do with my environment and testing everything I wrote in rails console so I could run rspec once (always works the first time) on a batch of methods between resets, because I couldn't find anything at all that would help fix this. When I noticed the migrations error arising even when I hadn't changed anything in my code, I dug around until I found something pointing at line 16.

Here's what it was:
config.use_transactional_fixtures = false

I changed it to "true" and it worked. Spent 2 hours on Ask trying to figure this out. We haven't covered anything in Rspec yet, so I didn't know where to begin looking. My methods still aren't all working and this lesson is already confusing enough as it is (the readme mentions Arel out of the blue and sends us to some fruitless documentation), so I've basically lost an entire day to this. It's extremely frustrating.

learn and rspec not working properly

after running rake db:migrate and rake db:migrate RAILS_ENV=test, learn and rspec files will only run once. After that it prompts to re-run rake db:migrate RAILS_ENV=test which throws an error every time (it won't migrate). The only solution @the-Widget found was to delete the test.sqlite3 file and run rake db:migrate RAILS_ENV=test, however you have to do this everytime you want to run a test.

This should note that you should use a rails command

This lab should not that you have to use the rails command "rails console" instead of rake console.

Also the file structure does not match what the prior read me has indicated.

ALSO AREL who knows what that is yet???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.