2

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;
3
  • YoddleJob.where(account_key: "YzI5ZDUyNWY5NmYwNWFiNjJiYmE1YTk4Y2VkYTBjYTZmOGM5ZTI0NzE2MzU2MzAwMmU2OWU2MzNiYmQ2YTZhMA==").select('next_refresh_time').limit(1) try this Commented Jun 2, 2015 at 11:15
  • is this query working? Commented Jun 2, 2015 at 12:28
  • Its works.. but doesn't choose the latest one - last record. Commented Jun 3, 2015 at 8:32

4 Answers 4

2

The equivalent query is

YoddleJob.select(:next_refresh_time).where(:account_key => "YzI5ZDUyNWY5NmYwNWFiNjJiYmE1YTk4Y2VkYTBjYTZmOGM5ZTI0NzE2MzU2MzAwMmU2OWU2MzNiYmQ‌​2YTZhMA==").last(1)
Sign up to request clarification or add additional context in comments.

Comments

2

You can try this

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

Comments

0

This should be like this

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.