From the course: Ruby on Rails 6 Essential Training: Models and Associations

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

More ActiveRecord query methods

More ActiveRecord query methods - Ruby on Rails Tutorial

From the course: Ruby on Rails 6 Essential Training: Models and Associations

Start my 1-month free trial

More ActiveRecord query methods

- [Instructor] In this movie we going to learn more active record query methods so that you can work smarter with your models. In the Ruby on Rails essential training, we learned the most basic kind of query methodologies, where, and where will take a number of arguments. We can pass in an hash, we can pass in an array, or we can pass in a string. Here you see I've got a hash, which is visible, true. Now this will find all the records where this one condition is true, that all the records are marked visible. But what if we want to have more than one condition? Well, for working with a hash, we can just simply add in a second parameter. Here I'm asking for all records where visible is true and sold out as false. And Ruby on Rails will write the SQL that's appropriate for that. It'll have an and clause in there. But this doesn't always work for us. Let's consider this case, here you can see I have visible true but I…

Contents