ruby – How to write this MySql query using Rails3 syntax? – Education Career Blog

SELECT  `subscriptions`.*, DATE_ADD(`subscriptions`.created_at, INTERVAL `packages`.validity DAY) as end_date
     FROM  `subscriptions`  INNER JOIN `packages` ON `packages`.`id` = `subscriptions`.`package_id`
    order by end_date;


Assuming you have a model Subscription that is a subclass of ActiveRecord::Base
Then it is simply just“subscriptions.*, DATE_ADD(subscriptions.created_at, INTERVAL packages.validity DAY) as end_date).joins(:packages).order(:end_date)

I may have some syntax wrong, such as it may be :package not :packages. But the basic

Leave a Comment