Find the Records in Rails Applications :: Using where , include ,eager loading , search and find_by :: + All others
Links ::
https://apidock.com/rails/ActiveRecord/Base/find/class
..............................................................................................................
..............................................................................................................
1. Product.where("name like ?","%apple%")
2. Product.where("name like ?","%c%").map(&:id)
3. Product.where("name like ?","%c%").map(&:name)
..............................................................................................................
Create the Bulk Records in Rails Application ::
1000000000.times do |i|
Product.create!(name: "product #{i}")
end
Note :: This method will be used if you want to use the bulk record .
..............................................................................................................
Destroy the Bulk Records in Rails Application ::
Product.where(:id => params[:ids]).destroy_all
Product.where(:id => [1,2,3,4]).destroy_all
..............................................................................................................
Find out the Record with Time Limit ?
Product.where(:created_at => 7.days.ago..1.day.ago).present?
Product.where(:created_at => 7.days.ago...Time.now).present?
Product.where(:created_at => 7.days.ago...Time.now)
record = Product.where(['created_at < ? AND updated_at > ?', 25/05/2022, 25/04/2025])
record = Product.where(['created_at < ? AND end_date > ?', 25/05/2022, 25/04/2025])
Note :: start_at and end_at are the columns in the table
Product.where('created_at > ? AND created_at < ?', Date.today + 12.hours, Date.today + 16.5.hours)
..............................................................................................................
Date.today.all_day..............................................................................................................
Create New Date through Console ::date = Date.new(2021, 4, 30)date - 7.days..............................................................................................................
Find the Record with id ::
Product.find([7, 17])
..............................................................................................................
Find the Record with column (dynamic finders) ::
product = Product.find_by_name("product1")..............................................................................................................
Comments
Post a Comment