Ninjinx
Ninjinx

Reputation: 645

Convert SQL Query to Rails ORM Query

Whats the eqivalent Rails ORM command for the SQL Query ?

select next_refresh_time from yoddle_jobs where account_key = "YzI5ZDUyNWY5NmYwNWFiNjJiYmE1YTk4Y2VkYTBjYTZmOGM5ZTI0NzE2MzU2MzAwMmU2OWU2MzNiYmQ2YTZhMA==" order by id DESC LIMIT 1;

Upvotes: 2

Views: 188

Answers (4)

Vrushali Pawar
Vrushali Pawar

Reputation: 3803

YoddleJob.where(account_key: "YzI5ZDUyNWY5NmYwNWFiNjJiYmE1YTk4Y2VkYTBjYTZmOGM5ZTI0NzE2MzU2MzAwMmU2OWU2MzNiYmQ‌​2YTZhMA==").select('next_refresh_time').last(1)

Upvotes: 0

Rajdeep Singh
Rajdeep Singh

Reputation: 17834

You can try this

YoddleJob.select(:next_refresh_time).where(account_key: "YzI5ZDUyNWY5NmYwNWFiNjJiYmE1YTk4Y2VkYTBjYTZmOGM5ZTI0NzE2MzU2MzAwMmU2OWU2MzNiYmQ‌​2YTZhMA==").order("id DESC").first

Upvotes: 2

Ninjinx
Ninjinx

Reputation: 645

The equivalent query is

YoddleJob.select(:next_refresh_time).where(:account_key => "YzI5ZDUyNWY5NmYwNWFiNjJiYmE1YTk4Y2VkYTBjYTZmOGM5ZTI0NzE2MzU2MzAwMmU2OWU2MzNiYmQ‌​2YTZhMA==").last(1)

Upvotes: 2

Sachin R
Sachin R

Reputation: 11876

This should be like this

YoddleJob.where(:account_key => "YzI5ZDUyNWY5NmYwNWFiNjJiYmE1YTk4Y2VkYTBjYTZmOGM5ZTI0NzE2MzU2MzAwMmU2OWU2MzNiYmQ2YTZhMA==").select('next_refresh_time').order("id desc").limit(1)

Upvotes: 0

Related Questions