Code Snippets

Home » activerecord
Where Clause Along with Associations in Rails

As a developer you will struggle with models associations but sometimes you may need only some record from an associations, and when you need it frequently you can create a separate association like so: has_many :remote_employees, -> {where(remote:true)}, class_name: 'Employee'

ActiveRecord greater/less Than Comparison

Many times you will find yourself query for some records in between of a range being it a date range or a numeric range. ActiveRecord allows you to use a Ruby range or incomplete range to query data in the database.